return SECURITY_MANAGER_SUCCESS;
}
+int fileStatus(const std::string &path)
+{
+ struct stat st;
+ if (-1 == lstat(path.c_str(), &st)) {
+ if (ENOENT == errno)
+ return 0; // no, file does not exist
+ return -1; // error
+
+ }
+ if (S_ISREG(st.st_mode))
+ return 1; // yes, file exists
+ return -1; // this is not a file -> error
+}
+
int createFile(const std::string &path)
{
int fd = open(path.c_str(), O_RDONLY|O_CREAT, 0644);
int directoryStatus(const std::string &path);
int createDirectory(const std::string &path);
int removeDirectory(const std::string &path);
+int fileStatus(const std::string &path);
int createFile(const std::string &path);
int removeFile(const std::string &path);
}
}
- ret = FS::createFile(appFile);
- if (ret != SECURITY_MANAGER_SUCCESS)
- return ret;
-
- MountNS::uMount(appFile);
+ if (FS::fileStatus(appFile) == 0) { // file does not exist
+ ret = FS::createFile(appFile);
+ if (ret != SECURITY_MANAGER_SUCCESS)
+ return ret;
+ } else {
+ MountNS::uMount(appFile);
+ }
ret = MountNS::bindMount(procFile, appFile);
if (ret != SECURITY_MANAGER_SUCCESS) {