Merge "[2.2.1][P130807-00904] Fail to get the host of the uri which has only ? charac...
[platform/framework/native/appfw.git] / src / io / FIo_DirectoryImpl.cpp
index 673ec90..28b8969 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -92,7 +91,7 @@ _DirectoryImpl::Construct(const String& dirPath)
        if (__pDir == null)
        {
                r = _NativeError::ConvertNativeErrorToResult(errno, true);
-               SysLog(NID_IO, "[%s] Failed to open directory (%s).", GetErrorMessage(r), pDirPath.get());
+               SysSecureLogException(NID_IO, r, "[%s] Failed to open directory (%s).", GetErrorMessage(r), pDirPath.get());
                goto CATCH;
        }
 
@@ -101,7 +100,6 @@ _DirectoryImpl::Construct(const String& dirPath)
        return E_SUCCESS;
 
 CATCH:
-
        return r;
 }
 
@@ -139,7 +137,7 @@ _DirectoryImpl::Create(const String& dirPath, bool createParentDirsToo)
 
        // By the time we are here.. we assume we have a legal path to create
        // the below logic works under the assumption that the path name does not end with '/'
-       ret = mkdir(pDirPath.get(), S_IRUSR | S_IWUSR | S_IXUSR);
+       ret = mkdir(pDirPath.get(), 0755);
        if (ret == -1)
        {
                // if parent directory does not exist and if we are asked to create them
@@ -361,8 +359,24 @@ _DirectoryImpl::Rename(const String& orgDirPath, const String& newDirPath)
        ret = rename(pOldpath.get(), pNewpath.get());
        if (ret != 0)
        {
-               r = _NativeError::ConvertNativeErrorToResult(errno, true);
-               SysLog(NID_IO, "errno[%d], [%s] could not rename dirpath [%s].", errno, GetErrorMessage(r), pOldpath.get());
+               switch (errno)
+               {
+               case EBUSY:
+               // fall through
+               case EMLINK:
+                       r = E_IO;
+                       break;
+               case ENOTEMPTY:
+                       r = E_FILE_ALREADY_EXIST;
+                       break;
+               case EXDEV:
+                       r = E_INVALID_ARG;
+                       break;
+               default:
+                       r = _NativeError::ConvertNativeErrorToResult(errno, true);
+                       break;
+               }
+               SysLogException(NID_IO, r, "[%s] Renaming the directory path (%s) is failed, errno: %d (%s)", GetErrorMessage(r), pOldpath.get(), errno, strerror(errno));
        }
 
        return r;
@@ -436,11 +450,10 @@ _DirectoryImpl::RemoveRecursively(char* pDirPath)
                strcpy(absPath, pDirPath);
                strcat(absPath, "/");
                strcat(absPath, dirEnt.d_name);
-               //SysLog(NID_IO, "entry name: %s", absPath);
 
-               struct stat statbuf;
-               memset(&statbuf, 0, sizeof(struct stat));
-               if (lstat(absPath, &statbuf) == -1)
+               struct stat64 statbuf;
+               memset(&statbuf, 0, sizeof(struct stat64));
+               if (lstat64(absPath, &statbuf) == -1)
                {
                        r = _NativeError::ConvertNativeErrorToResult(errno, true);
                        SysLog(NID_IO, "[%s] Failed to get file status. errno: %d (%s)",
@@ -449,7 +462,7 @@ _DirectoryImpl::RemoveRecursively(char* pDirPath)
                }
                if (!S_ISLNK(statbuf.st_mode))
                {
-                       if (stat(absPath, &statbuf) < 0)
+                       if (stat64(absPath, &statbuf) < 0)
                        {
                                r = _NativeError::ConvertNativeErrorToResult(errno, true);
                                SysLog(NID_IO, "[%s] Failed to get file status. errno: %d (%s)",