OsStatus OsDirLinux::create(int permissions) const { OsStatus ret = OS_INVALID; OsPathBase path; if (mDirName.getNativePath(path) == OS_SUCCESS) { int err = mkdir((const char *)path.data(),permissions); if (err != -1) { ret = OS_SUCCESS; } } return ret; }
OsStatus OsFileBase::rename(const OsPathBase& rNewFilename) { OsLock lock(fileMutex); #ifdef DEBUG_FS pthread_t nTaskId = 0; OsTask* pTask = OsTask::getCurrentTask(); if (pTask) pTask->id(nTaskId); Os::Logger::instance().log(FAC_KERNEL, PRI_DEBUG, "OsFileBase::rename ENTER threadid=%ld\n", nTaskId); #endif OsStatus ret = OS_INVALID; //if it's open then close it close(); int err = ::rename(mFilename.data(),rNewFilename.data()); if (err != -1) { ret = OS_SUCCESS; } else { // Rename failed, if there is a file that already exists having // the new name, try removing it first OsFile fileInPlace(rNewFilename); if(fileInPlace.exists()) { fileInPlace.remove(TRUE); // Try the move again int err2 = ::rename(mFilename.data(),rNewFilename.data()); if (err2 != -1) { ret = OS_SUCCESS; } } } #ifdef DEBUG_FS Os::Logger::instance().log(FAC_KERNEL, PRI_DEBUG, "OsFileBase::rename EXIT threadid=%ld\n", nTaskId); #endif return ret; }
OsStatus OsDirLinux::rename(const char* name) { OsStatus ret = OS_INVALID; OsPathBase path; if (mDirName.getNativePath(path) == OS_SUCCESS) { int err = ::rename(path.data(),name); if (err != -1) { ret = OS_SUCCESS; //make this object point to new path mDirName = name; } } return ret; }