introduce copy file utility

PiperOrigin-RevId: 683707504
This commit is contained in:
Anay Wadhera
2024-10-08 11:46:08 -07:00
committed by Copybara-Service
parent a70d4b096f
commit 117b13d099
2 changed files with 15 additions and 0 deletions
+10
View File
@@ -105,4 +105,14 @@ bool CreateHardLink(const std::filesystem::path& target,
return true;
}
bool CopyFileSafely(const std::filesystem::path& old_path,
const std::filesystem::path& new_path) {
std::error_code error_code;
std::filesystem::copy(old_path, new_path, error_code);
if (error_code) {
return false;
}
return true;
}
} // namespace nearby::sharing
+5
View File
@@ -56,6 +56,11 @@ bool CreateDirectories(const std::filesystem::path& path);
bool CreateHardLink(const std::filesystem::path& target,
const std::filesystem::path& link_path);
// Copies the file at old_path to new_path.
// Returns true on success.
bool CopyFileSafely(const std::filesystem::path& old_path,
const std::filesystem::path& new_path);
} // namespace nearby::sharing
#endif // THIRD_PARTY_NEARBY_INTERNAL_BASE_FILES_H_