REGISTER_ASYNC("FileSystemManager_mkdir", FileSystemManagerMakeDirectory);
REGISTER_SYNC("FileSystemManager_mkdirSync",
FileSystemManagerMakeDirectorySync);
+ REGISTER_ASYNC("File_unlinkFile", UnlinkFile);
#undef REGISTER_SYNC
#undef REGISTER_ASYNC
}
&FilesystemManager::ReadDir, &fm, pathToDir, onSuccess, onError));
}
+void FilesystemInstance::UnlinkFile(const picojson::value& args,
+ picojson::object& out) {
+ LoggerD("enter");
+ CHECK_EXIST(args, "pathToFile", out)
+
+ double callback_id = args.get("callbackId").get<double>();
+ const std::string& pathToFile = args.get("pathToFile").get<std::string>();
+
+ auto onSuccess = [this, callback_id]() {
+ LoggerD("enter");
+ picojson::value result = picojson::value();
+ picojson::value response = picojson::value(picojson::object());
+ picojson::object& obj = response.get<picojson::object>();
+ obj["callbackId"] = picojson::value(callback_id);
+ ReportSuccess(result, obj);
+ PostMessage(response.serialize().c_str());
+ };
+
+ auto onError = [this, callback_id](FilesystemError e) {
+ LoggerD("enter");
+ picojson::value response = picojson::value(picojson::object());
+ picojson::object& obj = response.get<picojson::object>();
+ obj["callbackId"] = picojson::value(callback_id);
+ PrepareError(e, obj);
+ PostMessage(response.serialize().c_str());
+ };
+
+ FilesystemManager& fm = FilesystemManager::GetInstance();
+ common::TaskQueue::GetInstance().Async(std::bind(
+ &FilesystemManager::UnlinkFile, &fm, pathToFile, onSuccess, onError));
+}
+
void FilesystemInstance::PrepareError(const FilesystemError& error, picojson::object& out)
{
LoggerD("enter");
return;
}
}
+
+void FilesystemManager::UnlinkFile(
+ const std::string& path,
+ const std::function<void()>& success_cb,
+ const std::function<void(FilesystemError)>& error_cb) {
+ if (unlink(path.c_str()) != 0) {
+ LoggerE("Error occured while deleting file");
+ error_cb(FilesystemError::Other);
+ return;
+ }
+ success_cb();
+}
} // namespace filesystem
} // namespace extension
public:
static FilesystemManager& GetInstance();
+ void UnlinkFile(
+ const std::string& path,
+ const std::function<void()>& success_cb,
+ const std::function<void(FilesystemError)>& error_cb);
+
void StatPath(const std::string& path,
const std::function<void(const FilesystemStat&)>& success_cb,
const std::function<void(FilesystemError)>& error_cb);