[patch] BackupPC_zipCreate

Alexander Moisseev <[email protected]>
Newsgroups gmane.comp.sysutils.backup.backuppc.devel
Message-ID <[email protected]>
- Switch default charset for encoding file names to utf8
- Set general purpose bit 11 for UTF-8 code page
- Set "version made by" field to 0 (MS-DOS) for OEM code pages


Testing

See some archivers tests results in attached zip-test.zip. This test shows which application lists filenames in zip archives created by BackupPC_zipCreate with different code pages and "Version made by" field values correctly (V) or incorrectly (X). Actually, tests was done for Russian (cp866, cp1251) and German (cp850, cp1252) code pages. General purpose bit 11 has been set for UTF-8 code page. "Version made by" field makes no sense for UTF-8.


Interpreting results

If "version made by" set to MS-DOS then "old" versions of applications uses OEM code page. If "version made by" set to UNIX then local ANSI code page. Recent versions of archivers and Zip Folders simply ignores "version made by" and always uses OEM. So OEM code page should be used rather then ANSI for better compatibility.
   E.g.
cp850 rather then cp1252,
cp866 rather then cp1251,
and so on.

Nowadays most of archivers support UTF-8. As utf8 is "language independent" it seems reasonable to select one as _default_ charset for encoding file names.


References

http://www.pkware.com/documents/casestudies/APPNOTE.TXT

--
Alexander

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery, 
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now. 
http://p.sf.net/sfu/quest-d2dcopy1

_______________________________________________
BackupPC-devel mailing list
[email protected]
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-devel
Wiki:    http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/
BackupPC_zipCreate.patch (text/plain, 3.3 KB)
diff -ruN BackupPC-3.2.1.orig/bin/BackupPC_zipCreate BackupPC-3.2.1/bin/BackupPC_zipCreate
--- BackupPC-3.2.1.orig/bin/BackupPC_zipCreate	Mon Apr 25 07:31:55 2011
+++ BackupPC-3.2.1/bin/BackupPC_zipCreate	Tue May 24 15:53:11 2011
@@ -21,7 +21,7 @@
 #       -r pathRemove   path prefix that will be replaced with pathAdd
 #       -p pathAdd      new path prefix
 #       -c level        compression level (default is 0, no compression)
-#       -e charset      charset for encoding file names (default: cp1252)
+#       -e charset      charset for encoding file names (default: utf8)
 #
 #     The -h, -n and -s options specify which dump is used to generate
 #     the zip archive.  The -r and -p options can be used to relocate
@@ -93,7 +93,7 @@
      -r pathRemove   path prefix that will be replaced with pathAdd
      -p pathAdd      new path prefix
      -c level        compression level (default is 0, no compression)
-     -e charset      charset for encoding file names (default: cp1252)
+     -e charset      charset for encoding file names (default: utf8)
 EOF
     exit(1);
 }
@@ -135,7 +135,7 @@
     exit(1);
 }
 
-my $Charset = "cp1252";
+my $Charset = ""; # default: utf8
 $Charset = $opts{e} if ( $opts{e} ne "" );
 
 my $PathRemove = $1 if ( $opts{r} =~ /(.+)/ );
@@ -310,6 +310,14 @@
     
     # Specify the compression level for this member
     $zipmember->desiredCompressionLevel($compLevel) if ($compLevel =~ /[0-9]/);
+    
+    if ( $Charset =~ /^(?:utf[-_]?8)?$/i ) {
+        # Set general purpose bit 11 for UTF-8 code page
+        $zipmember->{bitFlag} = $zipmember->{bitFlag} | 0x0800 ;
+    } elsif ( $Charset =~ /^cp(?:437|720|737|775|85[02578]|86[069]|874|93[26]|949|950)$/i ) {
+        # Set "version made by" field to 0 (MS-DOS) for OEM code pages
+        $zipmember->fileAttributeFormat('FA_MSDOS');
+    }
     
     # Finally Zip the member
     $zipfh->addMember($zipmember);
diff -ruN BackupPC-3.2.1.orig/doc/BackupPC.html BackupPC-3.2.1/doc/BackupPC.html
--- BackupPC-3.2.1.orig/doc/BackupPC.html	Mon Apr 25 07:31:55 2011
+++ BackupPC-3.2.1/doc/BackupPC.html	Tue May 24 09:28:33 2011
@@ -1664,7 +1664,7 @@
        -r pathRemove   path prefix that will be replaced with pathAdd
        -p pathAdd      new path prefix
        -c level        compression level (default is 0, no compression)
-       -e charset      charset for encoding file names (default: cp1252)</pre>
+       -e charset      charset for encoding file names (default: utf8)</pre>
 <p>The command-line files and directories are relative to the specified
 shareName.  The zip file is written to stdout. The -h, -n and -s
 options specify which dump is used to generate the zip archive.  The
diff -ruN BackupPC-3.2.1.orig/doc/BackupPC.pod BackupPC-3.2.1/doc/BackupPC.pod
--- BackupPC-3.2.1.orig/doc/BackupPC.pod	Mon Apr 25 07:31:55 2011
+++ BackupPC-3.2.1/doc/BackupPC.pod	Tue May 24 09:28:05 2011
@@ -1729,7 +1729,7 @@
        -r pathRemove   path prefix that will be replaced with pathAdd
        -p pathAdd      new path prefix
        -c level        compression level (default is 0, no compression)
-       -e charset      charset for encoding file names (default: cp1252)
+       -e charset      charset for encoding file names (default: utf8)
 
 The command-line files and directories are relative to the specified
 shareName.  The zip file is written to stdout. The -h, -n and -s
zip-test.zip (application/x-zip-compressed, 1.3 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.