[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Alternate fix for the hot-backup.py read-only file issue

From: <darkwing_at_proaxis.com>
Date: 2007-04-18 21:58:55 CEST

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.


<--- last part of the modified hot-backup.py script --->

### Step 5: finally, remove all repository backups other than the last

# 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)

To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Apr 23 21:53:18 2007

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.