Changeset 96575 in vbox
- Timestamp:
- Sep 2, 2022 8:53:37 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/testmanager/batch/maintain_archived_testsets.py
r96567 r96575 100 100 return True; 101 101 102 def _replaceFile(self, sDstFile, sSrcFile, fDryRun = False, fForce = False): 103 """ 104 Replaces / moves a file safely by backing up the existing destination file (if any). 105 106 Returns success indicator. 107 """ 108 109 # Rename the destination file first (if any). 110 sDstFileTmp = None; 111 if os.path.exists(sDstFile): 112 sDstFileTmp = sDstFile + ".bak"; 113 if os.path.exists(sDstFileTmp): 114 if not fForce: 115 print('Replace file: Warning: Temporary destination file "%s" already exists, skipping' % (sDstFileTmp,)); 116 return False; 117 else: 118 try: 119 os.remove(sDstFileTmp); 120 except Exception as e: 121 print('Replace file: Error deleting old temporary destination file "%s": %s' % (sDstFileTmp, e)); 122 return False; 123 try: 124 if not fDryRun: 125 shutil.move(sDstFile, sDstFileTmp); 126 except Exception as e: 127 print('Replace file: Error moving old destination file "%s" to temporary file "%s": %s' \ 128 % (sDstFile, sDstFileTmp, e)); 129 return False; 130 131 fRc = True; 132 133 try: 134 if not fDryRun: 135 shutil.move(sSrcFile, sDstFile); 136 except Exception as e: 137 print('Replace file: Error moving source file "%s" to destination "%s": %s' % (sSrcFile, sDstFile, e,)); 138 fRc = False; 139 140 if sDstFileTmp: 141 if fRc: # Move succeeded, remove backup. 142 try: 143 if not fDryRun: 144 os.remove(sDstFileTmp); 145 except Exception as e: 146 print('Replace file: Error deleting temporary destination file "%s": %s' % (sDstFileTmp, e)); 147 fRc = False; 148 else: # Final move failed, roll back. 149 try: 150 if not fDryRun: 151 shutil.move(sDstFileTmp, sDstFile); 152 except Exception as e: 153 print('Replace file: Error restoring old destination file "%s": %s' % (sDstFile, e)); 154 fRc = False; 155 return fRc; 156 102 157 def _processTestSetZip(self, idTestSet, sFile, sCurDir): 103 158 """ … … 148 203 hour = oCurFile.date_time[3], 149 204 minute = oCurFile.date_time[4], 150 second = oCurFile.date_time[5] ,);205 second = oCurFile.date_time[5]); 151 206 if tsFile < tsMaxAge: 152 207 self.dprint('\tIs older than %d days (%s)' % (self.cOlderThanDays, tsFile)) … … 169 224 oSrcZipFile.close(); 170 225 171 try: 172 self.dprint('Deleting ZIP file "%s"' % (sSrcZipFileAbs)); 173 if not self.fDryRun: 174 os.remove(sSrcZipFileAbs); 175 except Exception as oXcpt: 176 return (None, 'Error deleting ZIP file "%s": %s' % (sSrcZipFileAbs, oXcpt,), None); 177 try: 178 self.dprint('Moving ZIP "%s" to "%s"' % (sDstZipFileAbs, sSrcZipFileAbs)); 179 if not self.fDryRun: 180 shutil.move(sDstZipFileAbs, sSrcZipFileAbs); 181 except Exception as oXcpt5: 182 return (None, 'Error moving temporary ZIP "%s" to original ZIP file "%s": %s' \ 183 % (sDstZipFileAbs, sSrcZipFileAbs, oXcpt5,), None); 226 if fRc: 227 self.dprint('Moving file "%s" to "%s"' % (sDstZipFileAbs, sSrcZipFileAbs)); 228 fRc = self._replaceFile(sSrcZipFileAbs, sDstZipFileAbs, self.fDryRun); 229 184 230 except Exception as oXcpt3: 185 231 return (None, 'Error creating temporary ZIP archive "%s": %s' % (sDstZipFileAbs, oXcpt3,), None);
Note:
See TracChangeset
for help on using the changeset viewer.