diff --git a/mingw.c b/mingw.c index 956978f2..b1a5af7b 100644 --- a/mingw.c +++ b/mingw.c @@ -694,5 +694,10 @@ const char* windows_stat_desc(struct stat* st) return st->st_desc; } +void windows_sleep(unsigned seconds) +{ + Sleep(seconds * 1000); +} + #endif diff --git a/mingw.h b/mingw.h index 88158700..9d08d6f7 100644 --- a/mingw.h +++ b/mingw.h @@ -54,6 +54,7 @@ #define O_NOFOLLOW 0 #define stat_hidden windows_stat_hidden #define stat_desc windows_stat_desc +#define sleep windows_sleep /* In Windows symbolic links are not supported */ #define S_ISLNK(mode) 0 #define readlink(a,b,c) -1 @@ -213,6 +214,11 @@ int windows_stat_hidden(struct dirent* dd, struct windows_stat* st); */ const char* windows_stat_desc(struct stat* st); +/** + * Like sleep(). + */ +void windows_sleep(unsigned seconds); + #endif #endif diff --git a/snapraid.c b/snapraid.c index 6e0f6bb8..30a60927 100644 --- a/snapraid.c +++ b/snapraid.c @@ -307,6 +307,16 @@ int main(int argc, char* argv[]) if (state.need_write) state_write(&state); + /* waits some time to ensure that any concurrent modification done at the files, */ + /* using the same mtime read by the scan process, will be read by sync. */ + /* Note that any later modification done, potentially not read by sync, will have */ + /* a different mtime, and it will be syncronized at the next sync. */ + /* The worst case is the FAT filesystem with a two seconds resolution for mtime. */ + /* If you don't use FAT, the wait is not needed, because most filesystems have now */ + /* at least microseconds resolution, but better to be safe. */ + if (!test_skip_self) + sleep(2); + ret = state_sync(&state, blockstart, blockcount); /* save the new state if required */