Don't check file check when canonicalization 14/72014/2
authorKyungwook Tak <k.tak@samsung.com>
Mon, 30 May 2016 07:39:37 +0000 (16:39 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Mon, 30 May 2016 08:51:33 +0000 (17:51 +0900)
On client side, it's meaningless to check permission for file
access/remove when resolving absolute path for scanning because file
scanning isn't done with client's credential but server's cred. So when
resolving absolute path, it just append cwd if first char of path isn't
'/'.

Change-Id: Id453dc23553b20d88a91a96684bb010ffd4be27e
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/framework/client/canonicalize.cpp

index 428dd79..aa95d47 100644 (file)
@@ -22,8 +22,8 @@
 #include "client/canonicalize.h"
 
 #include <utility>
-#include <cstdlib>
 #include <cerrno>
+#include <unistd.h>
 
 #include "common/exception.h"
 
@@ -32,24 +32,27 @@ namespace Client {
 
 std::string getAbsolutePath(const std::string &path)
 {
-       auto resolved = realpath(path.c_str(), nullptr);
-       if (resolved == nullptr) {
-               int err = errno;
-               if (err == ENOENT)
-                       ThrowExc(FileDoNotExist, "File do not exist: " << path);
-               else if (err == EACCES)
-                       ThrowExc(FileSystemError, "Perm denied for a component of the "
-                                        "path prefix: " << path);
-               else
-                       ThrowExc(FileSystemError, "Failed to get resolved path: " << path <<
-                                        " errno: " << err);
+       if (path.empty() || path.front() == '/')
+               return path;
+
+       size_t bufsize = 1024;
+       std::vector<char> buf(bufsize, 0);
+
+       char *result = nullptr;
+
+       while ((result = ::getcwd(buf.data(), bufsize)) == nullptr && errno == ERANGE) {
+               bufsize <<= 1;
+               buf.resize(bufsize, 0);
        }
 
-       std::string resolvedStr(resolved);
+       if (result == nullptr)
+               ThrowExc(FileSystemError, "Failed to getcwd. errno: " << errno);
 
-       free(resolved);
+       std::string apath(buf.data());
+       apath += '/';
+       apath += path;
 
-       return resolvedStr;
+       return apath;
 }
 
 void canonicalizeDirSet(StrSet &dirset)