Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

19
LINES

< > BotCompany Repo | #1022129 // restoreLatestBackupIfConceptsFileEmpty

JavaX fragment (include)

svoid restoreLatestBackupIfConceptsFileEmpty(S dbID, O... _) {
  bool doIt = boolPar doIt(_);
  File file = conceptsFile(dbID);
  if (fileExists(file) && fileSize(file) == 0) {
    print(file + " corrupted, trying to restore");
    File backup = lastThat fileNotEmpty(sortByFileName(conceptBackupFiles(dbID)));
    if (backup == null) ret with print("No usable backup found :(");
    S msg = "RESTORING: " + backup;
    File log = javaxDataDir("db-restores.log");
    if (doIt) logQuotedWithTime(log, msg);
    print(stringIf(!doIt, "[would be] ") + msg);
    if (doIt) {
      clearConceptsOf(dbID);
      copyFile(backup, file);
      print(msg = "DB RESTORED!");
      if (doIt) logQuotedWithTime(log, msg);
    }
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022129
Snippet name: restoreLatestBackupIfConceptsFileEmpty
Eternal ID of this version: #1022129/4
Text MD5: 7e8ae744f58c50ef1b3c5c4842ff3db5
Author: stefan
Category: javax / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-08 10:33:55
Source code size: 740 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 249 / 305
Version history: 3 change(s)
Referenced in: [show references]