From 2f6fd23b841c1f4e3c18d1cbfd228784aa8c3298 Mon Sep 17 00:00:00 2001 From: John Denker Date: Sun, 29 Jul 2012 22:31:03 -0700 Subject: set40 appears to be working --- tools/libltgrey.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'tools/libltgrey.c') 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; +} -- cgit v1.2.3