@@ -36,7 +36,8 @@ OeisManager::OeisManager(const Settings &settings,
36
36
evaluator(settings),
37
37
finder(settings, evaluator),
38
38
finder_initialized(false ),
39
- update_needed(false ),
39
+ update_oeis(false ),
40
+ update_programs(false ),
40
41
optimizer(settings),
41
42
minimizer(settings),
42
43
loaded_count(0 ),
@@ -305,48 +306,78 @@ bool OeisManager::shouldMatch(const OeisSequence &seq) const {
305
306
void OeisManager::update () {
306
307
std::vector<std::string> files = {" stripped" , " names" };
307
308
308
- // check which files need to be updated
309
+ // check whether oeis files need to be updated
309
310
auto it = files.begin ();
310
- int64_t age_in_days = -1 ;
311
+ int64_t oeis_age_in_days = -1 ;
311
312
while (it != files.end ()) {
312
313
auto path = Setup::getOeisHome () + *it;
313
- age_in_days = getFileAgeInDays (path);
314
- if (age_in_days < 0 || age_in_days >= Setup::getUpdateIntervalInDays ()) {
315
- update_needed = true ;
314
+ oeis_age_in_days = getFileAgeInDays (path);
315
+ if (oeis_age_in_days < 0 ||
316
+ oeis_age_in_days >= Setup::getOeisUpdateInterval ()) {
317
+ update_oeis = true ;
316
318
break ;
317
319
}
318
320
it++;
319
321
}
320
- if (update_needed) {
322
+
323
+ // check whether programs need to be updated
324
+ const std::string progs_dir = Setup::getProgramsHome ();
325
+ const std::string local_dir = progs_dir + " local" ;
326
+ const std::string update_progs_file = local_dir + FILE_SEP + " .update" ;
327
+ int64_t programs_age_in_days = getFileAgeInDays (update_progs_file);
328
+ if (programs_age_in_days < 0 ) {
329
+ update_programs = update_oeis; // fall-back if file is not present
330
+ } else if (programs_age_in_days >= Setup::getGitHubUpdateInterval ()) {
331
+ update_programs = true ;
332
+ }
333
+
334
+ // perform oeis update
335
+ if (update_oeis) {
321
336
Setup::checkLatestedVersion ();
322
- if (age_in_days == -1 ) {
337
+ if (oeis_age_in_days == -1 ) {
323
338
Log::get ().info (" Creating OEIS index at \" " + Setup::getOeisHome () +
324
339
" \" " );
325
340
ensureDir (Setup::getOeisHome ());
326
341
} else {
327
342
Log::get ().info (" Updating OEIS index (last update " +
328
- std::to_string (age_in_days ) + " days ago)" );
343
+ std::to_string (oeis_age_in_days ) + " days ago)" );
329
344
}
330
345
std::string cmd, path;
331
346
for (auto &file : files) {
332
347
path = Setup::getOeisHome () + file;
333
348
ApiClient::getDefaultInstance ().getOeisFile (file, path);
334
349
}
335
- // update programs repository using git pull
350
+ }
351
+
352
+ // perform programs update
353
+ if (update_programs) {
336
354
auto mode = Setup::getMiningMode ();
337
- auto progs_dir = Setup::getProgramsHome ();
338
355
if (mode != MINING_MODE_SERVER && isDir (progs_dir + " .git" )) {
339
- Log::get ().info (" Updating programs repository" );
356
+ std::string msg (" Updating programs repository" );
357
+ if (programs_age_in_days >= 0 ) {
358
+ msg += " (last update " + std::to_string (programs_age_in_days) +
359
+ " days ago)" ;
360
+ }
361
+ Log::get ().info (msg);
362
+ // update programs repository using git pull
340
363
git (progs_dir, " pull origin main -q --ff-only" );
364
+ // touch marker file to track the age
365
+ ensureDir (update_progs_file);
366
+ std::ofstream marker (update_progs_file);
367
+ if (marker) {
368
+ marker << " 1" << std::endl;
369
+ } else {
370
+ Log::get ().warn (" Cannot write update marker: " + update_progs_file);
371
+ }
341
372
}
373
+
342
374
// clean up local programs folder
343
375
const int64_t max_age = Setup::getMaxLocalProgramAgeInDays ();
344
- const auto local = Setup::getProgramsHome () + " local" ;
345
- if (max_age >= 0 && isDir (local) &&
376
+ if (max_age >= 0 && isDir (local_dir) &&
346
377
Setup::getMiningMode () == MiningMode::MINING_MODE_CLIENT) {
347
378
Log::get ().info (" Cleaning up local programs directory" );
348
379
int64_t num_removed = 0 ;
349
- for (const auto &it : std::filesystem::directory_iterator (local )) {
380
+ for (const auto &it : std::filesystem::directory_iterator (local_dir )) {
350
381
const auto stem = it.path ().filename ().stem ().string ();
351
382
const auto ext = it.path ().filename ().extension ().string ();
352
383
bool is_program;
@@ -531,9 +562,11 @@ const Stats &OeisManager::getStats() {
531
562
stats.reset (new Stats ());
532
563
533
564
// check age of stats
565
+ auto update_interval = std::min<int64_t >(Setup::getOeisUpdateInterval (),
566
+ Setup::getGitHubUpdateInterval ());
534
567
auto age_in_days = getFileAgeInDays (stats->getMainStatsFile (stats_home));
535
- if (update_needed || age_in_days < 0 ||
536
- age_in_days >= Setup::getUpdateIntervalInDays () ) {
568
+ if (update_oeis || update_programs || age_in_days < 0 ||
569
+ age_in_days >= update_interval ) {
537
570
generateStats (age_in_days);
538
571
539
572
// generate lists in server mode
0 commit comments