> Attached is an alternate fix for the hot-backup.py and read-only file
> issue. I believe this is a cleaner solution since it does not use timeout
> delays, and it only traverses the directory tree one time. Also, the code
> that changes the file mode only runs if it is needed. Feel free to use
> any part of the script. I do my work in the windows environement, so I
> have not been able to test this script under Linux. If you try it under
> Linux, let me know the results.
Thanks for the patch! For those unfamiliar with the problem, do you
know have a more specific definition of it? That, or an issue number,
would go a long way toward helping reviewers look at your patch.
Including an appropriate log message, helps attract reviews, and gives
understanding to the problem you are trying to solve.
Also, submitting your patch in accordance with the patch guidelines
found in HACKING is the best way to get quick and helpful review.
Perhaps you can resubmit your patch, following these guidelines?
> <--- last part of the modified hot-backup.py script --->
> ### Step 5: finally, remove all repository backups other than the last
> ### NUM_BACKUPS.
> # Python cannot delete read-only files under Windows; this handler tries
> to remove the
> # the read-only protection and then delete the file.
> def handler(func, path, execinfo):
> # if this is called because we could not remove a file,
> # then see if it READONLY...
> if (func == os.remove) and not os.access(path, os.W_OK):
> # if it is READONLY, change it back to NORMAL and try again...
> os.chmod(path, stat.S_IWRITE)
> # something else must be wrong...
> if num_backups > 0:
> regexp = re.compile("^" + repo + "-[0-9]+(-[0-9]+)?" + ext_re + "$")
> directory_list = os.listdir(backup_dir)
> old_list = filter(lambda x: regexp.search(x), directory_list)
> del old_list[max(0,len(old_list)-num_backups):]
> for item in old_list:
> old_backup_item = os.path.join(backup_dir, item)
> print "Removing old backup: " + old_backup_item
> if os.path.isdir(old_backup_item):
> # specify an error handler to process read-only files
> shutil.rmtree(old_backup_item, False, handler)
Received on Mon Apr 23 22:35:35 2007