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

[PATCH] Fix hot-backup.py issue where zip archives do not backup empty directories

From: eg <egoots_at_gmail.com>
Date: Mon, 27 Oct 2008 23:16:22 -0700

Neels J. Hofmeyr wrote:

>
> I took a look at the python documentation, and it says this:
>
> [[[
> [ZipFile.]writestr( zinfo_or_arcname, bytes)
> Write the string bytes to the archive; zinfo_or_arcname is either the
> file name it will be given in the archive, or a ZipInfo instance. If it's an
> instance, at least the filename, date, and time must be given. If it's a
> name, the date and time is set to the current date and time. The archive
> must be opened with mode 'w' or 'a'.
> ]]]
>
> Have you paid attention to the date and time stuff?
>
> When I test your patch on GNU/Linux, empty directories are added with a date
> of 1980-01-01 00:00, which is not what the writestr() documentation says (if
> I understand that correctly).

hmmm... I must have mixed up reading the zinfo vs filename
initialization logic in the help string. In the zinfo case, giving no
time/date initializes it to 0 time which corresponds to the 1980-01-01
date/time. Not what the function needs nor what we want.

>
> Could you please investigate? We're close to a commit, but the date/time
> thing would be nice to clarify: Either fix it, or find a good reason why
> it's not needed.

I have fixed it in the attached patch.

> I'll commit as soon as the date/time thing is reviewed/resolved.

Thanks for your help and patience on this.

>
> For the record: while my `unzip' commandline tool successfully creates the
> empty directories as above, the Gnome Archive Manager fails to list them (so
> it's kind of a special case). I'd encourage using bz2 or gz instead. Most MS
> Windows software supports these archive types, so there's really no need to
> use zip archives in the first place (right?).
>

I did my testing with both 7-zip and winzip under WindowsXp and they
both re-create the directories correctly too. I also did a quick test
with InfoZip and that seemed to recreate the directory structure as well.

I am not sure if it is quite true that "most" windows software
supports bz2 or gz yet. However, it is true that it is becoming easier
to find tools that do (like 7-zip or the recently released Winzip 12).

Personally, I use bz2 for our production environment backup.

The revised patch is attached and here is the revised patch log message:

[[[
In the hot-backup.py script, also add empty directories to a Zip backup
(when using option --archive-type=zip). Implements this suggestion:
http://mail.python.org/pipermail/python-list/2004-June/266067.html

Patch by: eg <egoots_at_gmail.com>

* tools/backup/hot-backup.py.in (add_to_zip): Add empty directories to
      Zip files by explicitly writing the directory names with a trailing
      slash. Empty directories were previously omitted in Zip files.
]]]

Index: tools/backup/hot-backup.py.in
===================================================================
--- tools/backup/hot-backup.py.in (revision 33922)
+++ tools/backup/hot-backup.py.in (working copy)
@@ -301,13 +301,17 @@
       def add_to_zip(baton, dirname, names):
         zp = baton[0]
         root = os.path.join(baton[1], '')
-
- for file in names:
- path = os.path.join(dirname, file)
- if os.path.isfile(path):
- zp.write(path, path[len(root):])
- elif os.path.isdir(path) and os.path.islink(path):
- os.path.walk(path, add_to_zip, (zp, path))
+
+ if names == None or len(names) == 0:
+ zp.writestr(zipfile.ZipInfo(dirname[len(root):]+"/",
+ time.localtime(time.time())[:6]),"")
+ else:
+ for file in names:
+ path = os.path.join(dirname, file)
+ if os.path.isfile(path):
+ zp.write(path, path[len(root):])
+ elif os.path.isdir(path) and os.path.islink(path):
+ os.path.walk(path, add_to_zip, (zp, path))
             
       zp = zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED)
       os.path.walk(backup_subdir, add_to_zip, (zp, backup_dir))

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: dev-help_at_subversion.tigris.org
Received on 2008-10-28 11:02:16 CET

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