File_createSync attempts to create new file.
If file exists, then file is preserved.
Change-Id: Ie4262504be19d61dd3f500608e02ab6fe2b36163
Signed-off-by: Kamil Lysik <k.lysik@samsung.com>
RegisterHandler(c, std::bind(&FilesystemInstance::x, this, _1, _2));
REGISTER_ASYNC("File_stat", FileStat);
REGISTER_SYNC("File_statSync", FileStatSync);
+ REGISTER_SYNC("File_createSync", FileCreateSync);
REGISTER_SYNC("Filesystem_getWidgetPaths", FilesystemGetWidgetPaths);
REGISTER_SYNC("FileSystemManager_fetchStorages",
FileSystemManagerFetchStorages);
return; \
}
+void FilesystemInstance::FileCreateSync(const picojson::value& args, picojson::object& out)
+{
+ LoggerD("enter");
+ CHECK_EXIST(args, "location", out)
+
+ const std::string& location = args.get("location").get<std::string>();
+
+ auto onSuccess = [&](const FilesystemStat& data) {
+ LoggerD("enter");
+ ReportSuccess(data.toJSON(), out);
+ };
+
+ auto onError = [&](FilesystemError e) {
+ LoggerD("enter");
+ PrepareError(e, out);
+ };
+
+ FilesystemManager::GetInstance().CreateFile(location, onSuccess, onError);
+}
+
void FilesystemInstance::FileStat(const picojson::value& args,
picojson::object& out) {
LoggerD("enter");
virtual ~FilesystemInstance();
private:
+ void FileCreateSync(const picojson::value& args, picojson::object& out);
void FileStat(const picojson::value& args, picojson::object& out);
void FileStatSync(const picojson::value& args, picojson::object& out);
void FilesystemGetWidgetPaths(const picojson::value& args,
#include <package_manager.h>
#include <storage-expand.h>
#include <storage.h>
+#include <fcntl.h>
#include "common/logger.h"
#include "common/scope_exit.h"
result["wgt-private-tmp"] = app_root + "/tmp";
success_cb(result);
}
+
+void FilesystemManager::CreateFile(
+ const std::string& path,
+ const std::function<void(const FilesystemStat&)>& success_cb,
+ const std::function<void(FilesystemError)>& error_cb) {
+ const mode_t create_mode = S_IRWXU | S_IRWXG | S_IRWXO;
+ int status;
+ status =
+ TEMP_FAILURE_RETRY(open(path.c_str(), O_RDWR | O_CREAT, create_mode));
+ if (-1 == status) {
+ LoggerE("Cannot create or open file %s: %s", path.c_str(), strerror(errno));
+ error_cb(FilesystemError::Other);
+ }
+ status = close(status);
+ if (0 != status) {
+ LoggerE("Cannot close file %s: %s", path.c_str(), strerror(errno));
+ error_cb(FilesystemError::Other);
+ }
+ FilesystemStat stat = FilesystemStat::getStat(path);
+ if (stat.valid) {
+ success_cb(stat);
+ } else {
+ LoggerE("Cannot create stat data!");
+ error_cb(FilesystemError::Other);
+ }
}
-}
+} // namespace filesystem
+} // namespace extension
const std::function<void(const std::map<std::string, std::string>&)>&
success_cb,
const std::function<void(FilesystemError)>& error_cb);
+
+ void CreateFile(const std::string& path,
+ const std::function<void(const FilesystemStat&)>& success_cb,
+ const std::function<void(FilesystemError)>& error_cb);
};
} // namespace filesystem
} // namespace extension