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

Re: [PATCH] hot-backup archiving failes on Windows because of read-only files

From: Jens Peters <jpeters7677_at_gmx.de>
Date: 2007-03-18 10:36:19 CET

> I unfortunately don't have time to review the patch itself, but for
> crediting Chris Foote, you should use the "Patch by: " syntax in the
> log message.

Karl, thank you for your hint (and shame on me for not paying enough attention).
Next Try:

[[[
* hot-backup.py.in
   Replace os.rmtree with our own rmtree implementation
   so that we can remove read-only files on Windows.

Patch by: Chris Foote <cfoote@v21.me.uk>
]]]

Index: tools/backup/hot-backup.py.in
===================================================================
--- tools/backup/hot-backup.py.in (revision 23889)
+++ tools/backup/hot-backup.py.in (working copy)
@@ -22,7 +22,7 @@

  ######################################################################

-import sys, os, getopt, shutil, string, re
+import sys, os, getopt, stat, string, re

  ######################################################################
  # Global Settings
@@ -151,6 +151,34 @@

    return string.strip(stdout_lines[0])

+def rmtree(path):
+ # Re-implement rmtree so we can remove read-only files.
+ cmdtuples = []
+ arg = path
+
+ try:
+ _build_cmdtuple(path, cmdtuples)
+ for func, arg in cmdtuples:
+ func(arg)
+ except OSError:
+ exc = sys.exc_info()
+ # Re-raise the exception
+ raise exc[0], (exc[1][0], exc[1][1] + ' removing '+arg)
+
+def _build_cmdtuple(path, cmdtuples):
+ # Helper for rmtree()
+ for f in os.listdir(path):
+ real_f = os.path.join(path,f)
+ if os.path.isdir(real_f) and not os.path.islink(real_f):
+ _build_cmdtuple(real_f, cmdtuples)
+ else:
+ # The format file on Windows is read-only and can not be removed,
+ # make it writeable before removing.
+ if os.path.basename(real_f) == 'format':
+ cmdtuples.append((lambda x: os.chmod(x, stat.S_IWRITE), real_f))
+ cmdtuples.append((os.remove, real_f))
+ cmdtuples.append((os.rmdir, path))
+
  ######################################################################
  # Main

@@ -256,7 +284,7 @@
      sys.exit(err_code)
    else:
      print "Archive created, removing backup '" + backup_subdir + "'..."
- shutil.rmtree(backup_subdir)
+ rmtree(backup_subdir)

  ### Step 5: finally, remove all repository backups other than the last
  ### NUM_BACKUPS.
@@ -271,6 +299,6 @@
      old_backup_item = os.path.join(backup_dir, item)
      print "Removing old backup: " + old_backup_item
      if os.path.isdir(old_backup_item):
- shutil.rmtree(old_backup_item)
+ rmtree(old_backup_item)
      else:
        os.remove(old_backup_item)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun Mar 18 10:36:41 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.