From: Daniel Hokka Zakrisson Date: Sat, 27 Jan 2007 09:38:56 +0000 (+0000) Subject: Add an option (--ignore-mtime) to vhashify to hashify files with differing mtimes. X-Git-Tag: release-0.30.214~130 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20f606206a2cf6e9596e0ffebf3230a019518790;p=util-vserver.git Add an option (--ignore-mtime) to vhashify to hashify files with differing mtimes. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2475 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/lib_internal/unify.h b/lib_internal/unify.h index 60691eb..2c60257 100644 --- a/lib_internal/unify.h +++ b/lib_internal/unify.h @@ -46,14 +46,22 @@ Unify_isIUnlinkable(char const *filename) NONNULL((1)); ((bool)((LHS)->st_dev ==(RHS)->st_dev && \ (LHS)->st_ino ==(RHS)->st_ino)) -#define Unify_isUnifyable(LHS, RHS) \ +#define _Unify_isUnifyable(LHS, RHS) \ ((bool)((LHS)->st_dev ==(RHS)->st_dev && \ (LHS)->st_ino !=(RHS)->st_ino && \ (LHS)->st_mode ==(RHS)->st_mode && \ (LHS)->st_uid ==(RHS)->st_uid && \ (LHS)->st_gid ==(RHS)->st_gid && \ - (LHS)->st_size ==(RHS)->st_size && \ - (LHS)->st_mtime==(RHS)->st_mtime)) + (LHS)->st_size ==(RHS)->st_size)) +#ifdef UTIL_VSERVER_UNIFY_MTIME_OPTIONAL +# define Unify_isUnifyable(LHS, RHS) \ + ((bool)(_Unify_isUnifyable(LHS, RHS) && \ + (global_args->ignore_mtime || \ + (LHS)->st_mtime==(RHS)->st_mtime))) +#else +# define Unify_isUnifyable(LHS, RHS) \ + _Unify_isUnifyable(LHS, RHS) +#endif #endif // H_UTIL_VSERVER_LIB_INTERNAL_UNIFY_H diff --git a/src/vhashify.c b/src/vhashify.c index 49510de..1cfb875 100644 --- a/src/vhashify.c +++ b/src/vhashify.c @@ -20,6 +20,8 @@ # include #endif +#define UTIL_VSERVER_UNIFY_MTIME_OPTIONAL + #include "vhashify.h" #include "util.h" @@ -70,6 +72,7 @@ #define CMD_SLEDGE 0x1002 #define CMD_MANUALLY 0x1003 #define CMD_REFRESH 0x1004 +#define CMD_NOMTIME 0x1005 struct option const CMDLINE_OPTIONS[] = { @@ -80,6 +83,7 @@ CMDLINE_OPTIONS[] = { { "sledgehammer", no_argument, 0, CMD_SLEDGE }, { "manually", no_argument, 0, CMD_MANUALLY }, { "refresh", no_argument, 0, CMD_REFRESH }, + { "ignore-mtime", no_argument, 0, CMD_NOMTIME }, { "dry-run", no_argument, 0, 'n' }, { "verbose", no_argument, 0, 'v' }, { 0,0,0,0 } @@ -289,7 +293,7 @@ addStatHash(hashFunctionContext *h_ctx, struct stat const * const st) SET_ATTR(gid), SET_ATTR(rdev), SET_ATTR(size), - SET_ATTR(mtime) + .mtime = (global_args->ignore_mtime ? 0 : st->st_mtime), }; #undef SET_ATTR @@ -688,6 +692,7 @@ int main(int argc, char *argv[]) .insecure = 0, .dry_run = false, .do_refresh = false, + .ignore_mtime = false, }; Vector_init(&global_info.hash_dirs, sizeof(struct HashDirInfo)); @@ -706,6 +711,7 @@ int main(int argc, char *argv[]) case CMD_INSECURE : args.insecure = 1; break; case CMD_SLEDGE : args.insecure = 2; break; case CMD_REFRESH : args.do_refresh = true; break; + case CMD_NOMTIME : args.ignore_mtime = true; break; case 'n' : args.dry_run = true; break; case 'v' : ++args.verbosity; break; default : diff --git a/src/vhashify.h b/src/vhashify.h index 874a034..22beb63 100644 --- a/src/vhashify.h +++ b/src/vhashify.h @@ -32,6 +32,7 @@ struct Arguments { char const * hash_dir; bool dry_run; bool do_refresh; + bool ignore_mtime; }; struct HashDirInfo {