From 7c79e5f6ce1209f4689789b2712ad3d4e782498f Mon Sep 17 00:00:00 2001 From: morningman Date: Tue, 4 Jul 2023 22:46:32 +0800 Subject: [PATCH] 1 --- be/src/io/fs/local_file_system.cpp | 16 ++++++++++++++++ be/src/io/fs/local_file_system.h | 5 +++++ be/src/olap/single_replica_compaction.cpp | 3 +-- be/src/olap/task/engine_clone_task.cpp | 3 +-- be/src/runtime/snapshot_loader.cpp | 3 +-- be/src/service/backend_service.cpp | 3 +-- be/src/service/internal_service.cpp | 5 ++--- 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/be/src/io/fs/local_file_system.cpp b/be/src/io/fs/local_file_system.cpp index 9b5c8eec85c1e6..737b966e13d81d 100644 --- a/be/src/io/fs/local_file_system.cpp +++ b/be/src/io/fs/local_file_system.cpp @@ -45,6 +45,8 @@ namespace doris { namespace io { class FileReaderOptions; +std::filesystem::perms LocalFileSystem::PERMS_OWNER_RW = std::filesystem::perms::owner_read | std::filesystem::perms::owner_write; + std::shared_ptr LocalFileSystem::create(Path path, std::string id) { return std::shared_ptr(new LocalFileSystem(std::move(path), std::move(id))); } @@ -410,5 +412,19 @@ const std::shared_ptr& global_local_filesystem() { return local_fs; } +Status LocalFileSystem::permission(const Path& file, std::filesystem::perms prms) { + auto path = absolute_path(file); + FILESYSTEM_M(permission_impl(path, prms)); +} + +Status LocalFileSystem::permission_impl(const Path& file, std::filesystem::perms prms) { + std::error_code ec; + std::filesystem::permissions(file, prms, ec); + if (ec) { + return Status::IOError("failed to change file permission {}", file.native(), errcode_to_str(ec)); + } + return Status::OK(); +} + } // namespace io } // namespace doris diff --git a/be/src/io/fs/local_file_system.h b/be/src/io/fs/local_file_system.h index bcebd48a6547aa..00dca6e97c8a79 100644 --- a/be/src/io/fs/local_file_system.h +++ b/be/src/io/fs/local_file_system.h @@ -68,6 +68,10 @@ class LocalFileSystem final : public FileSystem { static bool contain_path(const Path& parent, const Path& sub); // delete dir or file Status delete_directory_or_file(const Path& path); + // change the file permission of the given path + Status permission(const Path& file, std::filesystem::perms prms); + + static std::filesystem::perms PERMS_OWNER_RW; protected: Status create_file_impl(const Path& file, FileWriterPtr* writer) override; @@ -92,6 +96,7 @@ class LocalFileSystem final : public FileSystem { Status get_space_info_impl(const Path& path, size_t* capacity, size_t* available); Status copy_dirs_impl(const Path& src, const Path& dest); Status delete_directory_or_file_impl(const Path& path); + Status permission_impl(const Path& file, std::filesystem::perms prms); private: LocalFileSystem(Path&& root_path, std::string&& id = ""); diff --git a/be/src/olap/single_replica_compaction.cpp b/be/src/olap/single_replica_compaction.cpp index 78e9b79514aabd..64b63f4fdc560a 100644 --- a/be/src/olap/single_replica_compaction.cpp +++ b/be/src/olap/single_replica_compaction.cpp @@ -481,8 +481,7 @@ Status SingleReplicaCompaction::_download_files(DataDir* data_dir, << ", local_file_size=" << local_file_size; return Status::InternalError("downloaded file size is not equal"); } - chmod(local_file_path.c_str(), S_IRUSR | S_IWUSR); - return Status::OK(); + return io::global_local_filesystem()->permission(local_file_path, io::LocalFileSystem::PERMS_OWNER_RW); }; RETURN_IF_ERROR(HttpClient::execute_with_retry(DOWNLOAD_FILE_MAX_RETRY, 1, download_cb)); } // Clone files from remote backend diff --git a/be/src/olap/task/engine_clone_task.cpp b/be/src/olap/task/engine_clone_task.cpp index 845cbe11171f60..4dc40f9c0b407c 100644 --- a/be/src/olap/task/engine_clone_task.cpp +++ b/be/src/olap/task/engine_clone_task.cpp @@ -490,8 +490,7 @@ Status EngineCloneTask::_download_files(DataDir* data_dir, const std::string& re << ", local_file_size=" << local_file_size; return Status::InternalError("downloaded file size is not equal"); } - chmod(local_file_path.c_str(), S_IRUSR | S_IWUSR); - return Status::OK(); + return io::global_local_filesystem()->permission(local_file_path, io::LocalFileSystem::PERMS_OWNER_RW); }; RETURN_IF_ERROR(HttpClient::execute_with_retry(DOWNLOAD_FILE_MAX_RETRY, 1, download_cb)); } // Clone files from remote backend diff --git a/be/src/runtime/snapshot_loader.cpp b/be/src/runtime/snapshot_loader.cpp index f1b58fa454c2f9..7eb58da2a00f7b 100644 --- a/be/src/runtime/snapshot_loader.cpp +++ b/be/src/runtime/snapshot_loader.cpp @@ -583,8 +583,7 @@ Status SnapshotLoader::remote_http_download( << ", local_file_size=" << local_file_size; return Status::InternalError("downloaded file size is not equal"); } - chmod(local_file_path.c_str(), S_IRUSR | S_IWUSR); - return Status::OK(); + return io::global_local_filesystem()->permission(local_file_path, io::LocalFileSystem::PERMS_OWNER_RW); }; RETURN_IF_ERROR(HttpClient::execute_with_retry(kDownloadFileMaxRetry, 1, download_cb)); diff --git a/be/src/service/backend_service.cpp b/be/src/service/backend_service.cpp index 76722ba858d9d6..44d4897c172441 100644 --- a/be/src/service/backend_service.cpp +++ b/be/src/service/backend_service.cpp @@ -619,8 +619,7 @@ void BackendService::ingest_binlog(TIngestBinlogResult& result, << ", local_file_size=" << local_file_size; return Status::InternalError("downloaded file size is not equal"); } - chmod(local_segment_path.c_str(), S_IRUSR | S_IWUSR); - return Status::OK(); + return io::global_local_filesystem()->permission(local_segment_path, io::LocalFileSystem::PERMS_OWNER_RW); }; auto status = HttpClient::execute_with_retry(max_retry, 1, get_segment_file_cb); diff --git a/be/src/service/internal_service.cpp b/be/src/service/internal_service.cpp index 7a936487c4d2e0..28c5a696a637ea 100644 --- a/be/src/service/internal_service.cpp +++ b/be/src/service/internal_service.cpp @@ -1215,7 +1215,6 @@ void PInternalServiceImpl::hand_shake(google::protobuf::RpcController* controlle constexpr char HttpProtocol[] = "http://"; constexpr char DownloadApiPath[] = "/api/_tablet/_download?token="; constexpr char FileParam[] = "&file="; -constexpr auto Permissions = S_IRUSR | S_IWUSR; std::string construct_url(const std::string& host_port, const std::string& token, const std::string& path) { @@ -1247,8 +1246,8 @@ static Status download_file_action(std::string& remote_file_url, std::string& lo return Status::InternalError("downloaded file size is not equal"); } } - chmod(local_file_path.c_str(), Permissions); - return Status::OK(); + + return io::global_local_filesystem()->permission(local_file_path, io::LocalFileSystem::PERMS_OWNER_RW); }; return HttpClient::execute_with_retry(DOWNLOAD_FILE_MAX_RETRY, 1, download_cb); }