Fix rsync unexpectly skip file
Normally rsync will skip any files that are already the same size and
have the same modification timestamp. Due to this, if 2 modify event
in one file happen in a short time, the second modify event will be
skipped by rsync.
This patch add a new option `-I` (--ignore-times) to rsync, which
sync file forcely even if the file size and modification timestamp
are the same.
Before this patch:
1. Prepare the file `foo`, content is:
```
123
```
2. Modify the file `foo` twice in a short time.
Note: Don't Change the File Size. I use this cpp code to mock.
```
\#include <fstream>
\#include <thread>
int main() {
std::ofstream file("foo");
file << "foo";
file.close();
std::this_thread::sleep_for(std::chrono::milliseconds(200));
std::ofstream file1("foo");
file1 << "bar";
file1.close();
return 0;
}
```
3. Check the syncd file, expect the content is `bar`, but the `foo`
was found.
After this patch the the file `foo` is synced always.
Change-Id: I25799319fed93631aa9d20b5b5efdd7391b585e1
Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
diff --git a/sync_manager.cpp b/sync_manager.cpp
index caafae0..b4f153d 100644
--- a/sync_manager.cpp
+++ b/sync_manager.cpp
@@ -51,8 +51,9 @@
}
}
- execl("/usr/bin/rsync", "rsync", "-a", entryPath.c_str(),
+ execl("/usr/bin/rsync", "rsync", "-aI", entryPath.c_str(),
dst.c_str(), nullptr);
+
// execl only returns on fail
error("Error ({ERRNO}) occurred during the rsync call on {PATH}",
"ERRNO", errno, "PATH", entryPath);