Skip to content

Commit 0761405

Browse files
committed
refactor(fs): rename LocalFile path accessor
1 parent 39851a5 commit 0761405

5 files changed

Lines changed: 33 additions & 33 deletions

File tree

src/paimon/fs/local/local_file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ LocalFile LocalFile::GetParentFile() const {
182182
}
183183
}
184184

185-
const std::string& LocalFile::GetAbsolutePath() const {
185+
const std::string& LocalFile::GetPath() const {
186186
return path_;
187187
}
188188

src/paimon/fs/local/local_file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LocalFile {
4545
Status List(std::vector<std::string>* file_list) const;
4646
Status ListFiles(std::vector<LocalFile>* file_list) const;
4747
Status Delete() const;
48-
const std::string& GetAbsolutePath() const;
48+
const std::string& GetPath() const;
4949
LocalFile GetParentFile() const;
5050
Result<bool> Mkdir() const;
5151
Result<std::unique_ptr<LocalFileStatus>> GetFileStatus() const;

src/paimon/fs/local/local_file_system.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Result<std::unique_ptr<OutputStream>> LocalFileSystem::Create(const std::string&
5454
}
5555
PAIMON_ASSIGN_OR_RAISE(LocalFile file, LocalFile::Create(path));
5656
LocalFile parent = file.GetParentFile();
57-
PAIMON_RETURN_NOT_OK(Mkdirs(parent.GetAbsolutePath()));
57+
PAIMON_RETURN_NOT_OK(Mkdirs(parent.GetPath()));
5858
PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<LocalOutputStream> out, LocalOutputStream::Create(file));
5959
return out;
6060
}
@@ -75,7 +75,7 @@ Status LocalFileSystem::MkdirsInternal(const LocalFile& file) const {
7575
} else {
7676
// exists and is not a directory -> is a regular file
7777
return Status::IOError(fmt::format("file {} already exists and is not a directory",
78-
file.GetAbsolutePath()));
78+
file.GetPath()));
7979
}
8080
}
8181

@@ -90,7 +90,7 @@ Status LocalFileSystem::MkdirsInternal(const LocalFile& file) const {
9090
return Status::OK();
9191
} else {
9292
return Status::IOError(
93-
fmt::format("create directory '{}' failed", file.GetAbsolutePath()));
93+
fmt::format("create directory '{}' failed", file.GetPath()));
9494
}
9595
}
9696
return Status::OK();
@@ -105,7 +105,7 @@ Result<std::unique_ptr<FileStatus>> LocalFileSystem::GetFileStatus(const std::st
105105
return Status::NotExist(
106106
fmt::format("File {} does not exist or the user running "
107107
"Paimon has insufficient permissions to access it.",
108-
file.GetAbsolutePath()));
108+
file.GetPath()));
109109
}
110110
}
111111

@@ -120,7 +120,7 @@ Status LocalFileSystem::ListDir(
120120
PAIMON_ASSIGN_OR_RAISE(bool is_file, file.IsFile());
121121
if (is_file) {
122122
return Status::IOError(
123-
fmt::format("file {} already exists and is not a directory", file.GetAbsolutePath()));
123+
fmt::format("file {} already exists and is not a directory", file.GetPath()));
124124
} else {
125125
std::vector<std::string> file_list;
126126
PAIMON_RETURN_NOT_OK(file.List(&file_list));
@@ -183,7 +183,7 @@ Status LocalFileSystem::Delete(const LocalFile& f, bool recursive) const {
183183
PAIMON_RETURN_NOT_OK(f.ListFiles(&files));
184184
if (recursive == false && !files.empty()) {
185185
return Status::IOError(
186-
fmt::format("cannot delete {}, directory is not empty", f.GetAbsolutePath()));
186+
fmt::format("cannot delete {}, directory is not empty", f.GetPath()));
187187
}
188188
for (const auto& file : files) {
189189
PAIMON_RETURN_NOT_OK(Delete(file));
@@ -212,8 +212,8 @@ Status LocalFileSystem::Rename(const std::string& src, const std::string& dst) c
212212
}
213213
PAIMON_ASSIGN_OR_RAISE(LocalFile dst_file, LocalFile::Create(dst));
214214
auto parent = dst_file.GetParentFile();
215-
PAIMON_RETURN_NOT_OK(Mkdirs(parent.GetAbsolutePath()));
216-
if (::rename(src_file.GetAbsolutePath().c_str(), dst_file.GetAbsolutePath().c_str()) != 0) {
215+
PAIMON_RETURN_NOT_OK(Mkdirs(parent.GetPath()));
216+
if (::rename(src_file.GetPath().c_str(), dst_file.GetPath().c_str()) != 0) {
217217
int32_t cur_errno = errno;
218218
return Status::IOError(err_msg, std::strerror(cur_errno));
219219
}
@@ -256,7 +256,7 @@ Result<int32_t> LocalInputStream::Read(char* buffer, uint32_t size) {
256256
PAIMON_ASSIGN_OR_RAISE(int32_t read_length, file_.Read(buffer, size));
257257
if (read_length != static_cast<int32_t>(size)) {
258258
return Status::IOError(fmt::format("file '{}' read size {} != expected {}",
259-
file_.GetAbsolutePath(), read_length, size));
259+
file_.GetPath(), read_length, size));
260260
}
261261
return read_length;
262262
}
@@ -265,7 +265,7 @@ Result<int32_t> LocalInputStream::Read(char* buffer, uint32_t size, uint64_t off
265265
PAIMON_ASSIGN_OR_RAISE(int32_t read_length, file_.Read(buffer, size, offset));
266266
if (read_length != static_cast<int32_t>(size)) {
267267
return Status::IOError(fmt::format("file '{}' read size {} != expected {}",
268-
file_.GetAbsolutePath(), read_length, size));
268+
file_.GetPath(), read_length, size));
269269
}
270270
return read_length;
271271
}

src/paimon/fs/local/local_file_system.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class LocalInputStream : public InputStream {
7474

7575
Status Close() override;
7676
Result<std::string> GetUri() const override {
77-
return file_.GetAbsolutePath();
77+
return file_.GetPath();
7878
}
7979
Result<uint64_t> Length() const override;
8080

@@ -93,7 +93,7 @@ class LocalOutputStream : public OutputStream {
9393
Status Flush() override;
9494
Status Close() override;
9595
Result<std::string> GetUri() const override {
96-
return file_.GetAbsolutePath();
96+
return file_.GetPath();
9797
}
9898

9999
private:

src/paimon/fs/local/local_file_test.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ TEST(LocalFileTest, TestReadWriteEmptyContent) {
2929
auto test_root_dir = UniqueTestDirectory::Create();
3030
ASSERT_TRUE(test_root_dir);
3131
std::string test_root = test_root_dir->Str();
32-
LocalFile dir = LocalFile(test_root);
32+
ASSERT_OK_AND_ASSIGN(auto dir, LocalFile::Create(test_root));
3333
if (dir.Exists().ok()) {
3434
ASSERT_TRUE(dir.Delete().ok());
3535
}
3636
ASSERT_OK_AND_ASSIGN(bool success, dir.Mkdir());
3737
ASSERT_TRUE(success);
3838
std::string path = test_root + "/test.txt";
39-
LocalFile file = LocalFile(path);
39+
ASSERT_OK_AND_ASSIGN(auto file, LocalFile::Create(path));
4040
if (file.Exists().ok()) {
4141
ASSERT_TRUE(file.Delete().ok());
4242
}
@@ -55,7 +55,7 @@ TEST(LocalFileTest, TestReadWriteEmptyContent) {
5555

5656
ASSERT_OK(file.Close());
5757

58-
LocalFile file2(path);
58+
ASSERT_OK_AND_ASSIGN(auto file2, LocalFile::Create(path));
5959
ASSERT_OK(file2.OpenFile(/*is_read_file=*/true));
6060
char buffer[10];
6161
ASSERT_OK_AND_ASSIGN(int32_t read_len, file2.Read(buffer, 10));
@@ -66,14 +66,14 @@ TEST(LocalFileTest, TestSimple) {
6666
auto test_root_dir = UniqueTestDirectory::Create();
6767
ASSERT_TRUE(test_root_dir);
6868
std::string test_root = test_root_dir->Str();
69-
LocalFile dir = LocalFile(test_root);
69+
ASSERT_OK_AND_ASSIGN(auto dir, LocalFile::Create(test_root));
7070
if (dir.Exists().ok()) {
7171
ASSERT_OK(dir.Delete());
7272
}
7373
ASSERT_OK_AND_ASSIGN(bool success, dir.Mkdir());
7474
ASSERT_TRUE(success);
7575
std::string path = test_root + "/test.txt";
76-
LocalFile file = LocalFile(path);
76+
ASSERT_OK_AND_ASSIGN(auto file, LocalFile::Create(path));
7777
if (file.Exists().ok()) {
7878
ASSERT_OK(file.Delete());
7979
}
@@ -102,7 +102,7 @@ TEST(LocalFileTest, TestSimple) {
102102
ASSERT_OK_AND_ASSIGN(size_t len, file.Length());
103103
ASSERT_EQ(len, str_size);
104104

105-
LocalFile file2 = LocalFile(path);
105+
ASSERT_OK_AND_ASSIGN(auto file2, LocalFile::Create(path));
106106
ASSERT_OK(file2.Exists());
107107

108108
ASSERT_OK(file2.OpenFile(true));
@@ -139,17 +139,17 @@ TEST(LocalFileTest, TestSimple) {
139139

140140
TEST(LocalFileTest, TestUsage) {
141141
std::string test_root = "local_file_test_usage";
142-
LocalFile dir = LocalFile(test_root);
142+
ASSERT_OK_AND_ASSIGN(auto dir, LocalFile::Create(test_root));
143143
ASSERT_OK_AND_ASSIGN(bool success, dir.Mkdir());
144144
ASSERT_TRUE(success);
145145
std::vector<std::string> file_list;
146146
ASSERT_OK(dir.List(&file_list));
147147
std::string path_deep_dir = test_root + "/tmp2";
148-
LocalFile deep_dir = LocalFile(path_deep_dir);
148+
ASSERT_OK_AND_ASSIGN(auto deep_dir, LocalFile::Create(path_deep_dir));
149149
ASSERT_OK_AND_ASSIGN(success, deep_dir.Mkdir());
150150
ASSERT_TRUE(success);
151151
LocalFile parent_deep_dir = deep_dir.GetParentFile();
152-
ASSERT_EQ(parent_deep_dir.GetAbsolutePath(), test_root);
152+
ASSERT_EQ(parent_deep_dir.GetPath(), dir.GetPath());
153153
ASSERT_OK(deep_dir.Delete());
154154
ASSERT_OK(parent_deep_dir.Delete());
155155
ASSERT_OK(dir.Delete());
@@ -159,14 +159,14 @@ TEST(LocalFileTest, TestOpenFile) {
159159
auto test_root_dir = UniqueTestDirectory::Create();
160160
ASSERT_TRUE(test_root_dir);
161161
std::string test_root = test_root_dir->Str();
162-
LocalFile dir = LocalFile(test_root);
162+
ASSERT_OK_AND_ASSIGN(auto dir, LocalFile::Create(test_root));
163163
if (dir.Exists().ok()) {
164164
ASSERT_OK(dir.Delete());
165165
}
166166
ASSERT_OK_AND_ASSIGN(bool success, dir.Mkdir());
167167
ASSERT_TRUE(success);
168168
std::string path = test_root + "/test.txt";
169-
LocalFile file = LocalFile(path);
169+
ASSERT_OK_AND_ASSIGN(auto file, LocalFile::Create(path));
170170
if (file.Exists().ok()) {
171171
ASSERT_OK(file.Delete());
172172
}
@@ -177,15 +177,15 @@ TEST(LocalFileTest, TestOpenFile) {
177177
ASSERT_NOK_WITH_MSG(dir.OpenFile(/*is_read_file=*/true), "cannot open a directory");
178178

179179
std::string path3 = "test.txt";
180-
LocalFile file3 = LocalFile(path3);
180+
ASSERT_OK_AND_ASSIGN(auto file3, LocalFile::Create(path3));
181181
ASSERT_OK(file3.OpenFile(/*is_read_file=*/false));
182182
ASSERT_OK_AND_ASSIGN(int64_t modify_time, file3.LastModifiedTimeMs());
183183
ASSERT_GE(modify_time, -1);
184184

185-
LocalFile dir2 = LocalFile("/");
185+
ASSERT_OK_AND_ASSIGN(auto dir2, LocalFile::Create("/"));
186186
ASSERT_OK_AND_ASSIGN(success, dir2.Mkdir());
187187
ASSERT_FALSE(success);
188-
LocalFile dir3 = LocalFile(test_root + "/");
188+
ASSERT_OK_AND_ASSIGN(auto dir3, LocalFile::Create(test_root + "/"));
189189
ASSERT_OK_AND_ASSIGN(success, dir3.Mkdir());
190190
ASSERT_FALSE(success);
191191
}
@@ -195,27 +195,27 @@ TEST(LocalFileTest, TestMkdir) {
195195
ASSERT_TRUE(test_root_dir);
196196
std::string test_root = test_root_dir->Str();
197197
{
198-
LocalFile dir = LocalFile(test_root + "tmp/local/f/1");
198+
ASSERT_OK_AND_ASSIGN(auto dir, LocalFile::Create(test_root + "tmp/local/f/1"));
199199
ASSERT_OK_AND_ASSIGN(bool success, dir.Mkdir());
200200
ASSERT_FALSE(success);
201201
}
202202
{
203-
LocalFile dir = LocalFile(test_root + "tmp1");
203+
ASSERT_OK_AND_ASSIGN(auto dir, LocalFile::Create(test_root + "tmp1"));
204204
ASSERT_OK_AND_ASSIGN(bool success, dir.Mkdir());
205205
ASSERT_TRUE(success);
206206
}
207207
{
208-
LocalFile dir = LocalFile(test_root + "tmp1/f2/");
208+
ASSERT_OK_AND_ASSIGN(auto dir, LocalFile::Create(test_root + "tmp1/f2/"));
209209
ASSERT_OK_AND_ASSIGN(bool success, dir.Mkdir());
210210
ASSERT_TRUE(success);
211211
}
212212
{
213-
LocalFile dir = LocalFile("/");
213+
ASSERT_OK_AND_ASSIGN(auto dir, LocalFile::Create("/"));
214214
ASSERT_OK_AND_ASSIGN(bool success, dir.Mkdir());
215215
ASSERT_FALSE(success);
216216
}
217217
{
218-
LocalFile dir = LocalFile("");
218+
ASSERT_OK_AND_ASSIGN(auto dir, LocalFile::Create(""));
219219
ASSERT_OK_AND_ASSIGN(bool success, dir.Mkdir());
220220
ASSERT_FALSE(success);
221221
}

0 commit comments

Comments
 (0)