diff options
-rw-r--r-- | tools/libltgrey.c | 47 | ||||
-rw-r--r-- | tools/libltgrey.h | 3 | ||||
-rw-r--r-- | tools/ltgrey.c | 12 |
3 files changed, 58 insertions, 4 deletions
diff --git a/tools/libltgrey.c b/tools/libltgrey.c index 38657e3..3a60daa 100644 --- a/tools/libltgrey.c +++ b/tools/libltgrey.c @@ -32,6 +32,11 @@ const int minimum_age(15*minute); const int maximum_age(32*day); const int probation(4*hour); +// beware: access illogically comes *before* modification +// in the array passed to utimes: +const int upd_ac(0); +const int upd_mod(1); + #if 0 void exeunt(const int sts){ if (sts == ex_good) exit(sts); @@ -195,7 +200,7 @@ int whatsit::doit(const int penalty, const int stain){ << ipname << "' : "; perror(0); } - ofstream foo; +//???!! ofstream foo; int fd = creat(ipname.c_str(), 0644); if (fd < 0){ cerr << progid << ": create failed for '" @@ -418,7 +423,45 @@ state_40 whatsit::get40(const string mid){ gettimeofday(&now, NULL); int mod_age = now.tv_sec - mid_stat.st_mtime; // int ac_age = now.tv_sec - mid_stat.st_atime; - if (mod_age < minimum_age) return young; + if (mod_age < minimum_age) return green; if (mod_age < probation) return ripe; return spoiled; } + +int whatsit::set40(const string mid, const int shift){ + string fname = parent_dir + "/quarante/mid_" + mid; + cerr << ".... " << fname << endl; + int fd = creat(fname.c_str(), 0644); + if (fd < 0){ + cerr << progid << ": create failed for '" + << fname << "' : "; + perror(0); + } + if (!shift) { + close(fd); + return 0; + } + + struct stat mid_stat; + int rslt = fstat(fd, &mid_stat); + close(fd); + if (rslt != 0) { + cerr << progid << " fstat: unexpected failure for '" + << fname << "' : "; + perror(0); + return ex_syserr; + } + + timeval now; + gettimeofday(&now, NULL); + timeval upd[2] = { + now, // access + now // modification + }; + upd[upd_mod].tv_sec += shift; + if (utimes(fname.c_str(), upd)){ + cerr << progid << " utimes failed!" << endl; + return ex_syserr; + } + return 0; +} diff --git a/tools/libltgrey.h b/tools/libltgrey.h index 1724d53..cf744d1 100644 --- a/tools/libltgrey.h +++ b/tools/libltgrey.h @@ -5,7 +5,7 @@ #define state_40_macro \ foo(unseen) \ -foo(young) \ +foo(green) \ foo(ripe) \ foo(spoiled) \ foo(fail) @@ -40,4 +40,5 @@ public: void dump(const std::string var); int maybe_mkdir(const std::string somedir, const std::string msg); state_40 get40(const std::string mid); + int set40(const std::string mid, const int shift); }; diff --git a/tools/ltgrey.c b/tools/ltgrey.c index 7a63b04..bb43b80 100644 --- a/tools/ltgrey.c +++ b/tools/ltgrey.c @@ -30,6 +30,7 @@ int main(int _argc, char** _argv){ int stain(0); int dns_mode(0); string get40_mid; + string set40_mid; while (argc > 0) { string arg = argv[0]; argc--; argv++; if (prefix(arg, "-scan")) { @@ -46,7 +47,12 @@ int main(int _argc, char** _argv){ exeunt(ex_syserr); } get40_mid = *argv++; argc--; - + } else if (prefix(arg, "-set40")) { + if (!argc){ + cerr << "Option '" << arg << "' requires an argument" << endl; + exeunt(ex_syserr); + } + set40_mid = *argv++; argc--; } else if (prefix(arg, "-shift") || prefix(arg, "-shift")) { if (!argc){ @@ -88,6 +94,10 @@ int main(int _argc, char** _argv){ return 0; } + if (set40_mid.length()){ + return foo.set40(set40_mid, shift); + } + if (scanmode) { string dirname = parent_dir + "/quarante"; scan(foo.progid, dirname, copies); |