Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
morningman committed Jul 4, 2023
1 parent 11e18f4 commit 7c79e5f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
16 changes: 16 additions & 0 deletions be/src/io/fs/local_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> LocalFileSystem::create(Path path, std::string id) {
return std::shared_ptr<LocalFileSystem>(new LocalFileSystem(std::move(path), std::move(id)));
}
Expand Down Expand Up @@ -410,5 +412,19 @@ const std::shared_ptr<LocalFileSystem>& 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
5 changes: 5 additions & 0 deletions be/src/io/fs/local_file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = "");
Expand Down
3 changes: 1 addition & 2 deletions be/src/olap/single_replica_compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions be/src/olap/task/engine_clone_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions be/src/runtime/snapshot_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
3 changes: 1 addition & 2 deletions be/src/service/backend_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions be/src/service/internal_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 7c79e5f

Please sign in to comment.