From f8be4baf5a2318363b42f8883f66ed8a976dfc79 Mon Sep 17 00:00:00 2001 From: John Denker Date: Sun, 29 Jul 2012 23:26:28 -0700 Subject: scan40 appears to be working, much cleaner than last week's version --- tools/ltgrey.c | 77 ++-------------------------------------------------------- 1 file changed, 2 insertions(+), 75 deletions(-) (limited to 'tools/ltgrey.c') diff --git a/tools/ltgrey.c b/tools/ltgrey.c index bb43b80..1494338 100644 --- a/tools/ltgrey.c +++ b/tools/ltgrey.c @@ -33,7 +33,7 @@ int main(int _argc, char** _argv){ string set40_mid; while (argc > 0) { string arg = argv[0]; argc--; argv++; - if (prefix(arg, "-scan")) { + if (prefix(arg, "-scan40")) { scanmode++; } else if (prefix(arg, "-copy")) { copies++; @@ -99,8 +99,7 @@ int main(int _argc, char** _argv){ } if (scanmode) { - string dirname = parent_dir + "/quarante"; - scan(foo.progid, dirname, copies); + foo.scan40(copies); return 0; } @@ -108,75 +107,3 @@ int main(int _argc, char** _argv){ return sts; } - -////////////////////////////////////////////////////////////////////// -// requires apt-get install libboost-filesystem-dev: -#include -#include -#include /* for stat(), getaddrinfo() */ -#include /* for stat() */ -#include /* for stat() */ -#include /* for perror */ -#include - -const int minute(60); -const int hour(60*minute); -const int day(24*hour); - -const int minimum_age(15*minute); -const int maximum_age(32*day); -const int probation(4*hour); - -void scan(const string progid, const string p, const int copies){ - timeval now; - gettimeofday(&now, NULL); - using namespace boost::filesystem; - - if (is_directory(p)) { - for (directory_iterator itr(p); itr!=directory_iterator(); ++itr) { - string basename = itr->path().filename(); - for (int ii = 0; ii < copies; ii++) - cout << setw(20) << left << basename << ' '; // display filename only - if (is_regular_file(itr->status())) { -// cout << " [" << file_size(itr->path()) << ']'; - struct stat mystat; - string fn = p + "/" + basename; - int rslt = stat(fn.c_str(), &mystat); - if (rslt != 0){ - cerr << progid << ": stat failed for '" - << fn << "' : "; - perror(0); - } - int mod_age = now.tv_sec - mystat.st_mtime; - int ac_age = now.tv_sec - mystat.st_atime; - cout << setw(10) << time_out(mod_age) - << " " << setw(10) << time_out(ac_age); - if (0) { - - } else if (mod_age < 0) { - cout << " penalty"; - } else if (mod_age < ac_age) { - cout << " parole"; - } else if (mod_age - ac_age < minimum_age // early bird, or completely unused - && mod_age > probation) { // did not diligently resubmit - cout << " disprobation"; - if (mod_age != ac_age) cout << "!"; - } else if (mod_age < minimum_age) { - cout << " young"; - if (mod_age != ac_age) cout << "!"; - } else if (mod_age == ac_age) { - cout << " unused"; - } else if (mod_age > maximum_age) { - cout << " expired"; - } else { - cout << " OK"; - } - } - cout << '\n'; - } - } - else { - // starting point is not a directory: - cout << (exists(p) ? "Found: " : "Not found: ") << p << '\n'; - } -} -- cgit v1.2.3