Merge change 2359 into donut
* changes:
Fix for the simultor build breakage.
diff --git a/libs/utils/backup_helper_file.cpp b/libs/utils/backup_helper_file.cpp
index 8efb3eb..7ec2ce8 100644
--- a/libs/utils/backup_helper_file.cpp
+++ b/libs/utils/backup_helper_file.cpp
@@ -26,6 +26,7 @@
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/stat.h>
+#include <sys/time.h> // for utimes
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -607,14 +608,14 @@
0x11, 0x00, 0x00, 0x00, 0x62, 0x79, 0x74, 0x65,
0x73, 0x5f, 0x6f, 0x66, 0x5f, 0x70, 0x61, 0x64,
0x64, 0x69, 0x6e, 0x67, 0x33, 0xab, 0xab, 0xab,
-
+
// bytes of padding2
0x44, 0x11, 0x22, 0x33, 0xef, 0xbe, 0xad, 0xde,
0x44, 0x33, 0x22, 0x11, 0x34, 0x23, 0x12, 0x01,
0x12, 0x00, 0x00, 0x00, 0x62, 0x79, 0x74, 0x65,
0x73, 0x5f, 0x6f, 0x66, 0x5f, 0x70, 0x61, 0x64,
0x64, 0x69, 0x6e, 0x67, 0x5f, 0x32, 0xab, 0xab,
-
+
// bytes of padding3
0x44, 0x11, 0x22, 0x33, 0xef, 0xbe, 0xad, 0xde,
0x44, 0x33, 0x22, 0x11, 0x34, 0x23, 0x12, 0x01,
@@ -627,7 +628,7 @@
if (err != 0) {
return err;
}
-
+
// read
fd = open(filename, O_RDONLY);
if (fd == -1) {
@@ -665,7 +666,7 @@
matched = false;
}
}
-
+
return matched ? 0 : 1;
}
@@ -746,7 +747,7 @@
system("rm -r " SCRATCH_DIR);
mkdir(SCRATCH_DIR, 0777);
mkdir(SCRATCH_DIR "data", 0777);
-
+
fd = creat(filename, 0666);
if (fd == -1) {
fprintf(stderr, "error creating: %s\n", strerror(errno));
@@ -863,7 +864,7 @@
system("rm -r " SCRATCH_DIR);
mkdir(SCRATCH_DIR, 0777);
mkdir(SCRATCH_DIR "data", 0777);
-
+
fd = creat(filename, 0666);
if (fd == -1) {
fprintf(stderr, "error creating: %s\n", strerror(errno));
@@ -940,9 +941,23 @@
return errno;
}
times[0].tv_sec = st.st_atime;
- times[0].tv_usec = st.st_atime_nsec / 1000;
times[1].tv_sec = st.st_mtime;
+
+ // If st_atime is a macro then struct stat64 uses struct timespec
+ // to store the access and modif time values and typically
+ // st_*time_nsec is not defined. In glibc, this is controlled by
+ // __USE_MISC.
+#ifdef __USE_MISC
+#if !defined(st_atime) || defined(st_atime_nsec)
+#error "Check if this __USE_MISC conditional is still needed."
+#endif
+ times[0].tv_usec = st.st_atim.tv_nsec / 1000;
+ times[1].tv_usec = st.st_mtim.tv_nsec / 1000;
+#else
+ times[0].tv_usec = st.st_atime_nsec / 1000;
times[1].tv_usec = st.st_mtime_nsec / 1000;
+#endif
+
return 0;
}
@@ -987,7 +1002,7 @@
{
BackupDataWriter dataStream(dataStreamFD);
-
+
err = back_up_files(-1, &dataStream, newSnapshotFD, SCRATCH_DIR, files_before, 5);
if (err != 0) {
return err;
@@ -1017,7 +1032,7 @@
utimes(SCRATCH_DIR "data/e", e_times);
write_text_file(SCRATCH_DIR "data/g", "g\ngg\n");
unlink(SCRATCH_DIR "data/f");
-
+
char const* files_after[] = {
"data/a", // added
"data/b", // same
@@ -1047,7 +1062,7 @@
{
BackupDataWriter dataStream(dataStreamFD);
-
+
err = back_up_files(oldSnapshotFD, &dataStream, newSnapshotFD, SCRATCH_DIR,
files_after, 6);
if (err != 0) {
@@ -1058,7 +1073,7 @@
close(oldSnapshotFD);
close(dataStreamFD);
close(newSnapshotFD);
-
+
return 0;
}