erofs-utils: lib: tar: fix garbage ns timestamps
authorGao Xiang <hsiangkao@linux.alibaba.com>
Sun, 14 Jul 2024 04:41:19 +0000 (12:41 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Sun, 14 Jul 2024 04:45:22 +0000 (12:45 +0800)
Some "#if" directives were used incorrectly.

Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240714044119.1119717-1-hsiangkao@linux.alibaba.com
include/erofs/defs.h
lib/tar.c

index 310a6aba34c9aec62cbcb21aea0f743cc6e2e635..e4623389af64033f75265bbbdc361bf57907da45 100644 (file)
@@ -332,15 +332,18 @@ unsigned long __roundup_pow_of_two(unsigned long n)
 #define ST_ATIM_NSEC(stbuf) ((stbuf)->st_atim.tv_nsec)
 #define ST_CTIM_NSEC(stbuf) ((stbuf)->st_ctim.tv_nsec)
 #define ST_MTIM_NSEC(stbuf) ((stbuf)->st_mtim.tv_nsec)
+#define ST_MTIM_NSEC_SET(stbuf, val) (stbuf)->st_mtim.tv_nsec = (val)
 #elif defined(HAVE_STRUCT_STAT_ST_ATIMENSEC)
 /* macOS */
 #define ST_ATIM_NSEC(stbuf) ((stbuf)->st_atimensec)
 #define ST_CTIM_NSEC(stbuf) ((stbuf)->st_ctimensec)
 #define ST_MTIM_NSEC(stbuf) ((stbuf)->st_mtimensec)
+#define ST_MTIM_NSEC_SET(stbuf, val) (stbuf)->st_mtimensec = (val)
 #else
 #define ST_ATIM_NSEC(stbuf) 0
 #define ST_CTIM_NSEC(stbuf) 0
 #define ST_MTIM_NSEC(stbuf) 0
+#define ST_MTIM_NSEC_SET(stbuf, val) do { } while (0)
 #endif
 
 #define __erofs_likely(x)      __builtin_expect(!!(x), 1)
index cefda3750edaa9a480ebad36649f0001e4d3b90b..a9b425ec4cc0462f5d5485300ef86388681dadef 100644 (file)
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -490,9 +490,9 @@ int tarerofs_parse_pax_header(struct erofs_iostream *ios,
                                                ret = -EIO;
                                                goto out;
                                        }
-#if ST_MTIM_NSEC
-                                       ST_MTIM_NSEC(&eh->st) = n;
-#endif
+                                       ST_MTIM_NSEC_SET(&eh->st, n);
+                               } else {
+                                       ST_MTIM_NSEC_SET(&eh->st, 0);
                                }
                                eh->use_mtime = true;
                        } else if (!strncmp(kv, "size=",
@@ -733,13 +733,12 @@ restart:
 
        if (eh.use_mtime) {
                st.st_mtime = eh.st.st_mtime;
-#if ST_MTIM_NSEC
-               ST_MTIM_NSEC(&st) = ST_MTIM_NSEC(&eh.st);
-#endif
+               ST_MTIM_NSEC_SET(&st, ST_MTIM_NSEC(&eh.st));
        } else {
                st.st_mtime = tarerofs_parsenum(th->mtime, sizeof(th->mtime));
                if (errno)
                        goto invalid_tar;
+               ST_MTIM_NSEC_SET(&st, 0);
        }
 
        if (th->typeflag <= '7' && !eh.path) {