-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Refactor pstd/env with std::filesystem #1470
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,12 +111,11 @@ bool StableLog::PurgeFiles(uint32_t to, bool manual) { | |
} | ||
|
||
// Do delete | ||
pstd::Status s = pstd::DeleteFile(log_path_ + it->second); | ||
if (s.ok()) { | ||
if (pstd::DeleteFile(log_path_ + it->second)) { | ||
++delete_num; | ||
--remain_expire_num; | ||
} else { | ||
LOG(WARNING) << log_path_ << " Purge log file : " << (it->second) << " failed! error:" << s.ToString(); | ||
LOG(WARNING) << log_path_ << " Purge log file : " << (it->second) << " failed! error: delete file failed"; | ||
} | ||
} else { | ||
// Break when face the first one not satisfied | ||
|
@@ -209,11 +208,11 @@ Status StableLog::PurgeFileAfter(uint32_t filenum) { | |
for (auto& it : binlogs) { | ||
if (it.first > filenum) { | ||
// Do delete | ||
Status s = pstd::DeleteFile(log_path_ + it.second); | ||
if (!s.ok()) { | ||
return s; | ||
auto filename = log_path_ + it.second; | ||
if (!pstd::DeleteFile(filename)) { | ||
return Status::IOError("pstd::DeleteFile faield, filename = " + filename); | ||
} | ||
LOG(WARNING) << "Delete file " << log_path_ + it.second; | ||
LOG(WARNING) << "Delete file " << filename; | ||
} | ||
} | ||
return Status::OK(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code patch seems to be a review of a piece of code that deals with purging files. Here are a few points about the code:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall, the code patch looks fine. However, there are a few improvements that could be made:
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,9 +42,16 @@ target_include_directories(pstd | |
${INSTALL_INCLUDEDIR} | ||
) | ||
|
||
target_link_libraries(pstd | ||
PUBLIC ${GLOG_LIBRARY} | ||
${GFLAGS_LIBRARY} | ||
${FMT_LIBRARY} | ||
${LIBUNWIND_LIBRARY} | ||
) | ||
set(PSTD_DEP_LIBS ${GLOG_LIBRARY} ${GFLAGS_LIBRARY} ${FMT_LIBRARY} ${LIBUNWIND_LIBRARY}) | ||
|
||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
if(CMAKE_CXX_COMPILER_VERSION LESS 9) | ||
list(APPEND PSTD_DEP_LIBS stdc++fs) | ||
endif() | ||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
if(CMAKE_CXX_COMPILER_VERSION LESS 9) | ||
list(APPEND PSTD_DEP_LIBS c++fs) | ||
endif() | ||
endif() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code patch seems to be adding support for linking the C++ filesystem library for GNU and Clang compilers based on their IDs. Here are some suggestions:
|
||
target_link_libraries(pstd PUBLIC ${PSTD_DEP_LIBS}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code patch modifies the CMake project file for a target named "pstd". The patch adds a condition to link the standard C++ file system library " A possible improvement to this patch is to use the Another potential improvement is to add a comment explaining the reason for linking the file system library only on specific compiler versions. Without proper documentation, future maintainers might not understand why the library is linked conditionally, leading to confusion and potential bugs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code patch seems to be modifying the CMake build script for the The changes appear to add conditional linker flags/arguments to link against the There are no obvious bug risks in this code patch, but it is always good to test the changes and ensure they work as intended. As for improvement suggestions, it is not clear from this code patch if there are any other areas that could be improved without more context and knowledge about the project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code patch seems to update the The changes look reasonable, as it defines an intermediate The additional code checks for the compiler type and version. If the compiler is GCC or Clang and its version is less than 9, it appends the One potential improvement could be to use |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ uint64_t Du(const std::string& filename); | |
*/ | ||
bool FileExists(const std::string& path); | ||
|
||
Status DeleteFile(const std::string& fname); | ||
bool DeleteFile(const std::string& fname); | ||
|
||
int RenameFile(const std::string& oldname, const std::string& newname); | ||
|
||
|
@@ -57,11 +57,8 @@ class FileLock : public pstd::noncopyable { | |
std::string name_; | ||
}; | ||
|
||
Status LockFile(const std::string& f, FileLock** l); | ||
Status UnlockFile(FileLock* l); | ||
|
||
int GetChildren(const std::string& dir, std::vector<std::string>& result); | ||
bool GetDescendant(const std::string& dir, std::vector<std::string>& result); | ||
void GetDescendant(const std::string& dir, std::vector<std::string>& result); | ||
|
||
uint64_t NowMicros(); | ||
void SleepForMicroseconds(int micros); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the provided diff, here are a few observations:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code patch seems to change the return type of the Without seeing the implementation of these functions or the context in which they are used, it is hard to determine whether these changes introduce any bugs or potential improvements. However, changing the return types could break compatibility with existing code that uses these functions, so it is important to make sure any other code using these functions is updated accordingly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code patch looks like a simple header file with function signatures and declarations, so it's hard to provide any concrete feedback without seeing the implementation details. However, some general suggestions include:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code patch seems to be a header file defining various file-related functions and classes. Here are some observations:
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code patch looks fine.
There is an improvement suggestion that can be made, where instead of concatenating strings in the
DeleteFile
function call, it will be better to pass it as a separate parameter.So instead of:
It should be:
This can help make the code more understandable and avoid any string concatenation issues.