summaryrefslogtreecommitdiff
path: root/tools/libltgrey.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-29 22:31:03 -0700
committerJohn Denker <jsd@av8n.com>2012-07-29 22:31:03 -0700
commit2f6fd23b841c1f4e3c18d1cbfd228784aa8c3298 (patch)
treeeed4240258bad34d68f260709574b50c68944f8f /tools/libltgrey.c
parent67eb4c6c804c728db329a7f4a77d5a3cbd1b993c (diff)
set40 appears to be working
Diffstat (limited to 'tools/libltgrey.c')
-rw-r--r--tools/libltgrey.c47
1 files changed, 45 insertions, 2 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;
+}