Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions be/src/io/fs/local_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
namespace doris {
namespace io {

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 @@ -453,5 +456,19 @@ Status LocalFileSystem::_glob(const std::string& pattern, std::vector<std::strin
return Status::OK();
}

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'permission_impl' can be made static [readability-convert-member-functions-to-static]

be/src/io/fs/local_file_system.h:100:

-     Status permission_impl(const Path& file, std::filesystem::perms prms);
+     static Status permission_impl(const Path& file, std::filesystem::perms prms);

std::error_code ec;
std::filesystem::permissions(file, prms, ec);
if (ec) {
return localfs_error(ec, fmt::format("failed to change file permission {}", file.native()));
}
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 @@ -62,6 +62,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;

Status canonicalize_local_file(const std::string& dir, const std::string& file_path,
std::string* full_path);
Expand Down Expand Up @@ -94,6 +98,7 @@ class LocalFileSystem final : public FileSystem {
const std::function<bool(const FileInfo&)>& cb);
Status get_space_info_impl(const Path& path, size_t* capacity, size_t* available);
Status copy_path_impl(const Path& src, const Path& dest);
Status permission_impl(const Path& file, std::filesystem::perms prms);

private:
// a wrapper for glob(), return file list in "res"
Expand Down
4 changes: 2 additions & 2 deletions be/src/olap/single_replica_compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ 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
4 changes: 2 additions & 2 deletions be/src/olap/task/engine_clone_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ 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
4 changes: 2 additions & 2 deletions be/src/runtime/snapshot_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ 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
5 changes: 3 additions & 2 deletions be/src/service/backend_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "gutil/strings/split.h"
#include "gutil/strings/substitute.h"
#include "http/http_client.h"
#include "io/fs/local_file_system.h"
#include "olap/olap_common.h"
#include "olap/olap_define.h"
#include "olap/rowset/beta_rowset.h"
Expand Down Expand Up @@ -272,8 +273,8 @@ void _ingest_binlog(StorageEngine& engine, IngestBinlogArg* arg) {
<< ", 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
6 changes: 3 additions & 3 deletions be/src/service/internal_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,6 @@ void PInternalService::hand_shake(google::protobuf::RpcController* controller,
constexpr char HttpProtocol[] = "http://";
constexpr char DownloadApiPath[] = "/api/_tablet/_download?token=";
constexpr char FileParam[] = "&file=";
constexpr auto Permissions = S_IRUSR | S_IWUSR;

static std::string construct_url(const std::string& host_port, const std::string& token,
const std::string& path) {
Expand Down Expand Up @@ -1480,8 +1479,9 @@ 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