summaryrefslogtreecommitdiff
path: root/tools/libltgrey.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-30 06:26:28 (GMT)
committerJohn Denker <jsd@av8n.com>2012-07-30 06:26:28 (GMT)
commitf8be4baf5a2318363b42f8883f66ed8a976dfc79 (patch)
tree9f747a0423647b016376fe353ceea197a5848cbf /tools/libltgrey.c
parent2f6fd23b841c1f4e3c18d1cbfd228784aa8c3298 (diff)
scan40 appears to be working, much cleaner than last week's version
Diffstat (limited to 'tools/libltgrey.c')
-rw-r--r--tools/libltgrey.c63
1 files changed, 52 insertions, 11 deletions
diff --git a/tools/libltgrey.c b/tools/libltgrey.c
index 3a60daa..4e92665 100644
--- a/tools/libltgrey.c
+++ b/tools/libltgrey.c
@@ -32,11 +32,6 @@ 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);
@@ -408,8 +403,16 @@ done:
}
state_40 whatsit::get40(const string mid){
- string fname = parent_dir + "/quarante/mid_" + mid;
- cerr << ".... " << fname << endl;
+ timeval junk[2];
+ return get40(mid, junk);
+}
+
+state_40 whatsit::get40(const string mid, timeval times[2]){
+ timeval now;
+ gettimeofday(&now, NULL);
+ times[0] = times[1] = now; // in case of early return
+ string fname = parent_dir + "/quarante/mid_" + purify(mid);
+ //xxx cerr << ".... " << fname << endl;
struct stat mid_stat;
int rslt = stat(fname.c_str(), &mid_stat);
if (rslt != 0) {
@@ -419,8 +422,10 @@ state_40 whatsit::get40(const string mid){
perror(0);
return fail;
}
- timeval now;
- gettimeofday(&now, NULL);
+ times[upd_ac ].tv_sec = mid_stat.st_atime;
+ times[upd_ac ].tv_usec = 0;
+ times[upd_mod].tv_sec = mid_stat.st_mtime;
+ times[upd_mod].tv_usec = 0;
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 green;
@@ -429,8 +434,8 @@ state_40 whatsit::get40(const string mid){
}
int whatsit::set40(const string mid, const int shift){
- string fname = parent_dir + "/quarante/mid_" + mid;
- cerr << ".... " << fname << endl;
+ string fname = parent_dir + "/quarante/mid_" + purify(mid);
+ //xxx cerr << ".... " << fname << endl;
int fd = creat(fname.c_str(), 0644);
if (fd < 0){
cerr << progid << ": create failed for '"
@@ -465,3 +470,39 @@ int whatsit::set40(const string mid, const int shift){
}
return 0;
}
+
+void whatsit::scan40(const int copies){
+ timeval now;
+ gettimeofday(&now, NULL);
+ using namespace boost::filesystem;
+
+ string dir40 = parent_dir + "/quarante";
+
+ if (is_directory(dir40)) {
+ for (directory_iterator itr(dir40); itr!=directory_iterator(); ++itr) {
+ string basename = itr->path().filename();
+ if (is_regular_file(itr->status())) {
+ string tag("mid_");
+ if (prefix(tag, basename)) {
+ for (int ii = 0; ii < copies; ii++)
+ cout << setw(20) << left << basename; // display filename only
+
+ timeval times[2];
+ state_40 rslt = get40(basename.substr(tag.length()), times);
+ int mod_age = now.tv_sec - times[upd_mod].tv_sec;
+ int ac_age = now.tv_sec - times[upd_ac ].tv_sec;
+ cout << setw(10) << right << time_out(mod_age)
+ << " " << setw(10) << right << time_out(ac_age);
+ cout << " " << decode_40[rslt];
+ cout << endl;
+ } else {
+ /* filename does not begin with tag "mid_" */
+ }
+ }
+ }
+ }
+ else {
+ // starting point is not a directory:
+ cout << (exists(dir40) ? "Found: " : "Not found: ") << dir40 << '\n';
+ }
+}