Expand path variables for sync destination (#18)

Expand path variables for sync destination

Running commands like cdc_rsync C:\assets\* host:~/assets -vr would create a directory called ~assets. This CL expands path variables properly.
This commit is contained in:
Lutz Justen
2022-11-25 14:21:21 +01:00
committed by GitHub
parent 991f61cc4d
commit 8c4a0465e9
5 changed files with 19 additions and 13 deletions

View File

@@ -100,14 +100,14 @@ FileFinderAndSender::FileFinderAndSender(PathFilter* path_filter,
recursive_(recursive), recursive_(recursive),
relative_(relative), relative_(relative),
request_size_threshold_(request_byte_threshold) { request_size_threshold_(request_byte_threshold) {
// (internal): Support / instead of \ in the source folder. // Support / instead of \ in the source folder.
path::FixPathSeparators(&sources_dir_); path::FixPathSeparators(&sources_dir_);
} }
FileFinderAndSender::~FileFinderAndSender() = default; FileFinderAndSender::~FileFinderAndSender() = default;
absl::Status FileFinderAndSender::FindAndSendFiles(std::string source) { absl::Status FileFinderAndSender::FindAndSendFiles(std::string source) {
// (internal): Support / instead of \ in sources. // Support / instead of \ in sources.
path::FixPathSeparators(&source); path::FixPathSeparators(&source);
// Special case, "." and ".." should not specify the directory, but the files // Special case, "." and ".." should not specify the directory, but the files
// inside this directory! // inside this directory!

View File

@@ -303,7 +303,7 @@ absl::Status CdcRsyncServer::HandleSetOptions() {
existing_ = request.existing(); existing_ = request.existing();
copy_dest_ = request.copy_dest(); copy_dest_ = request.copy_dest();
// (internal): Support \ instead of / in destination folders. // Support \ instead of / in destination folders.
path::FixPathSeparators(&destination_); path::FixPathSeparators(&destination_);
path::EnsureEndsWithPathSeparator(&destination_); path::EnsureEndsWithPathSeparator(&destination_);
if (!copy_dest_.empty()) { if (!copy_dest_.empty()) {
@@ -311,6 +311,13 @@ absl::Status CdcRsyncServer::HandleSetOptions() {
path::EnsureEndsWithPathSeparator(&copy_dest_); path::EnsureEndsWithPathSeparator(&copy_dest_);
} }
// Expand e.g. ~.
status = path::ExpandPathVariables(&destination_);
if (!status.ok()) {
return WrapStatus(status, "Failed to expand destination '%s'",
destination_);
}
assert(path_filter_.IsEmpty()); assert(path_filter_.IsEmpty());
for (int n = 0; n < request.filter_rules_size(); ++n) { for (int n = 0; n < request.filter_rules_size(); ++n) {
std::string fixed_pattern = request.filter_rules(n).pattern(); std::string fixed_pattern = request.filter_rules(n).pattern();

View File

@@ -80,9 +80,9 @@ class AsyncFileWatcher {
files_changed_cb_(std::move(files_changed_cb)), files_changed_cb_(std::move(files_changed_cb)),
dir_recreated_cb_(std::move(dir_recreated_cb)), dir_recreated_cb_(std::move(dir_recreated_cb)),
timeout_ms_(timeout_ms) { timeout_ms_(timeout_ms) {
// (internal): Check whether ReadDirectoryChangesExW is available. // Check whether ReadDirectoryChangesExW is available. It requires Windows
// It requires Windows 10, version 1709, released October 17, 2017, or // 10, version 1709, released October 17, 2017, or Corresponding Windows
// corresponding Windows Server versions. // Server versions.
if (!enforceLegacyReadDirectoryChangesForTesting) { if (!enforceLegacyReadDirectoryChangesForTesting) {
read_directory_changes_ex_ = read_directory_changes_ex_ =
reinterpret_cast<decltype(ReadDirectoryChangesExW)*>(::GetProcAddress( reinterpret_cast<decltype(ReadDirectoryChangesExW)*>(::GetProcAddress(

View File

@@ -119,9 +119,9 @@ ProcessStartInfo RemoteUtil::BuildProcessStartInfoForSsh(
ProcessStartInfo RemoteUtil::BuildProcessStartInfoForSshPortForward( ProcessStartInfo RemoteUtil::BuildProcessStartInfoForSshPortForward(
int local_port, int remote_port, bool reverse) { int local_port, int remote_port, bool reverse) {
// (internal): Usually, one would pass in -N here, but this makes the // Usually, one would pass in -N here, but this makes the connection terribly
// connection terribly slow! As a workaround, don't use -N (will open a // slow! As a workaround, don't use -N (will open a shell), but simply eat the
// shell), but simply eat the output. // output.
ProcessStartInfo si = BuildProcessStartInfoForSshInternal( ProcessStartInfo si = BuildProcessStartInfoForSshInternal(
GetPortForwardingArg(local_port, remote_port, reverse) + "-n ", ""); GetPortForwardingArg(local_port, remote_port, reverse) + "-n ", "");
si.stdout_handler = [](const void*, size_t) { return absl::OkStatus(); }; si.stdout_handler = [](const void*, size_t) { return absl::OkStatus(); };

View File

@@ -613,10 +613,9 @@ TEST_F(ManifestUpdaterTest, UpdateAll_LargeIntermediateIndirectDirAssets) {
cfg_.src_dir = path::Join(base_dir_, "non_empty"); cfg_.src_dir = path::Join(base_dir_, "non_empty");
ManifestUpdater updater(&data_store_, cfg_); ManifestUpdater updater(&data_store_, cfg_);
// (internal): Run UpdateAll() with intermediate manifest push. The push // Run UpdateAll() with intermediate manifest push. The push causes a Flush()
// causes a Flush() call to the manifest builder, which pushes some assets to // call to the manifest builder, which pushes some assets to indirect lists.
// indirect lists. This used to invalidate pointers and cause asserts to // This used to invalidate pointers and cause asserts to trigger.
// trigger.
EXPECT_OK(updater.UpdateAll(&file_chunks_, [](const ContentIdProto&) {})); EXPECT_OK(updater.UpdateAll(&file_chunks_, [](const ContentIdProto&) {}));
} }