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

[PATCH] Re: problem: hot-backup failing with access denied error

From: Chris Foote <cfoote_at_v21.me.uk>
Date: 2006-11-16 01:55:31 CET

2006/11/14, Norbert Unterberg:
> 2006/11/14, Daniel Rall <dlr@collab.net>:
> On Tue, 14 Nov 2006, Norbert Unterberg wrote:
> [... lengthy text about hot-backup.py failing because of write
> protected files deleted ...]
> > > Analysis shows:
> > > * the db\format file is write protected on all our repositories
> > > * hot-backup.py keeps the write protect flag when performing the copy
> > > * The shutil.rmtree(old_backup_subdir) command in hot-backup.py fails
> > > because the file is write protected.
[snip]
> > Norbert, are any other files in your repository backup area
> > write-protected?
> It is only the two format files: format and db/format. For whatever
> reason, svnadmin create sets the write protect flag just on that two
> files.

I've had this patch lying around in my setup for sometime now. At the time that
I
discovered it I thought that no one else must be using hot-backup on windows,
otherwise it would have been reported. Since then I'd forgotten about it.

Hope this helps.
Chris

[[[
Use our own rmtree so that we can make the format file writeable before
being removed, as it's read-only on Windows.

* tools/backup/hot-backup.py.in
  (rmtree): New. Re-implement rmtree so we can remove read-only files.
  (_build_cmdtuple): New. Helper for rmtree.

  Step 4, use our rmtree.
  Step 5, ditto.

]]]

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

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

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

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

   return string.strip(stdout_lines[0])

+# Re-implement rmtree so we can remove read-only files.
+def rmtree(path):
+ 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)
+
+# Helper for rmtree()
+def _build_cmdtuple(path, cmdtuples):
+ 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 Mon Nov 20 14:27:26 2006

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