rdiff-backup-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Rdiff-backup-commits] rdiff-backup/rdiff_backup eas_acls.py metadata...


From: Josh Nisly
Subject: [Rdiff-backup-commits] rdiff-backup/rdiff_backup eas_acls.py metadata....
Date: Thu, 04 Jun 2009 23:50:58 +0000

CVSROOT:        /sources/rdiff-backup
Module name:    rdiff-backup
Changes by:     Josh Nisly <joshn>      09/06/04 23:50:58

Modified files:
        rdiff_backup   : eas_acls.py metadata.py rpath.py statistics.py 

Log message:
        Gah. Fix unicode support for linux systems where the destination Python 
installation doesn't support unicode filenames.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/rdiff_backup/eas_acls.py?cvsroot=rdiff-backup&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/rdiff_backup/metadata.py?cvsroot=rdiff-backup&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/rdiff_backup/rpath.py?cvsroot=rdiff-backup&r1=1.140&r2=1.141
http://cvs.savannah.gnu.org/viewcvs/rdiff-backup/rdiff_backup/statistics.py?cvsroot=rdiff-backup&r1=1.24&r2=1.25

Patches:
Index: eas_acls.py
===================================================================
RCS file: /sources/rdiff-backup/rdiff-backup/rdiff_backup/eas_acls.py,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- eas_acls.py 18 Apr 2009 21:54:18 -0000      1.45
+++ eas_acls.py 4 Jun 2009 23:50:58 -0000       1.46
@@ -180,8 +180,11 @@
                raise metadata.ParsingError("Bad record beginning: " + 
first[:8])
        filename = first[8:]
        if filename == '.': index = ()
-       else: index = tuple(unicode(C.acl_unquote(encode(filename)),
-                                                                               
        'utf-8').split('/'))
+       else:
+               unquoted_filename = C.acl_unquote(encode(filename))
+               if Globals.use_unicode_paths:
+                       unquoted_filename = unicode(unquoted_filename, 'utf-8')
+               index = tuple(unquoted_filename.split('/'))
        ea = ExtendedAttributes(index)
 
        for line in lines:
@@ -556,8 +559,11 @@
                raise metadata.ParsingError("Bad record beginning: "+ 
first_line)
        filename = first_line[8:]
        if filename == '.': index = ()
-       else: index = tuple(unicode(C.acl_unquote(encode(filename)),
-                                               'utf-8').split('/'))
+       else:
+               unquoted_filename = C.acl_unquote(encode(filename))
+               if Globals.use_unicode_paths:
+                       unquoted_filename = unicode(unquoted_filename, 'utf-8')
+               index = tuple(unquoted_filename.split('/'))
        return AccessControlLists(index, record[newline_pos:])
 
 class ACLExtractor(EAExtractor):

Index: metadata.py
===================================================================
RCS file: /sources/rdiff-backup/rdiff-backup/rdiff_backup/metadata.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- metadata.py 9 Apr 2009 13:59:19 -0000       1.33
+++ metadata.py 4 Jun 2009 23:50:58 -0000       1.34
@@ -376,17 +376,17 @@
                        compress = 1
                if mode == 'r':
                        self.rp = rp_base
-                       self.fileobj = rpath.UnicodeFile(self.rp.open("rb", 
compress))
+                       self.fileobj = rpath.MaybeUnicode(self.rp.open("rb", 
compress))
                else:
                        assert mode == 'w'
                        if compress and check_path and not 
rp_base.isinccompressed():
                                def callback(rp): self.rp = rp
-                               self.fileobj = 
rpath.UnicodeFile(rpath.MaybeGzip(rp_base,
+                               self.fileobj = 
rpath.MaybeUnicode(rpath.MaybeGzip(rp_base,
                                                                                
                callback))
                        else:
                                self.rp = rp_base
                                assert not self.rp.lstat(), self.rp
-                               self.fileobj = 
rpath.UnicodeFile(self.rp.open("wb", 
+                               self.fileobj = 
rpath.MaybeUnicode(self.rp.open("wb", 
                                                                                
                compress = compress))
 
        def write_record(self, record):

Index: rpath.py
===================================================================
RCS file: /sources/rdiff-backup/rdiff-backup/rdiff_backup/rpath.py,v
retrieving revision 1.140
retrieving revision 1.141
diff -u -b -r1.140 -r1.141
--- rpath.py    18 Apr 2009 21:54:18 -0000      1.140
+++ rpath.py    4 Jun 2009 23:50:58 -0000       1.141
@@ -1417,19 +1417,24 @@
                write_win_acl(self, acl)
                self.data['win_acl'] = acl
 
-class UnicodeFile:
-       """ Wraps a RPath and reads/writes unicode. """
+class MaybeUnicode:
+       """ Wraps a RPath and reads/writes unicode if Globals.use_unicode_paths 
is on. """
 
        def __init__(self, fileobj):
                self.fileobj = fileobj
 
        def read(self, length = -1):
-               return unicode(self.fileobj.read(length), 'utf-8')
+               data = self.fileobj.read(length)
+               if Globals.use_unicode_paths:
+                       data = unicode(data, 'utf-8')
+               return data
 
        def write(self, buf):
+               if Globals.use_unicode_paths:
                if type(buf) != unicode:
                        buf = unicode(buf, 'utf-8')
-               return self.fileobj.write(buf.encode('utf-8'))
+                       buf = buf.encode('utf-8')
+               return self.fileobj.write(buf)
 
        def close(self):
                return self.fileobj.close()
@@ -1463,7 +1468,7 @@
                unicode with the filename."""
                if mode and 'b' not in mode:
                        mode += 'b'
-               if type(filename) != unicode:
+               if type(filename) != unicode and Globals.use_unicode_paths:
                        filename = unicode(filename, 'utf-8')
                fileobj = open(filename, mode or 'rb')
                gzip.GzipFile.__init__(self, filename.encode('utf-8'),

Index: statistics.py
===================================================================
RCS file: /sources/rdiff-backup/rdiff-backup/rdiff_backup/statistics.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- statistics.py       9 Apr 2009 13:59:19 -0000       1.24
+++ statistics.py       4 Jun 2009 23:50:58 -0000       1.25
@@ -219,13 +219,13 @@
 
        def write_stats_to_rp(self, rp):
                """Write statistics string to given rpath"""
-               fp = rpath.UnicodeFile(rp.open("wb"))
+               fp = rpath.MaybeUnicode(rp.open("wb"))
                fp.write(self.get_stats_string())
                assert not fp.close()
 
        def read_stats_from_rp(self, rp):
                """Set statistics from rpath, return self for convenience"""
-               fp = rpath.UnicodeFile(rp.open("r"))
+               fp = rpath.MaybeUnicode(rp.open("r"))
                self.set_stats_from_string(fp.read())
                fp.close()
                return self
@@ -364,7 +364,7 @@
                suffix = Globals.compression and 'data.gz' or 'data'
                cls._rp = increment.get_inc(rpbase, suffix, Time.curtime)
                assert not cls._rp.lstat()
-               cls._fileobj = rpath.UnicodeFile(cls._rp.open("wb", 
+               cls._fileobj = rpath.MaybeUnicode(cls._rp.open("wb", 
                                                        compress = 
Globals.compression))
 
                cls._line_sep = Globals.null_separator and '\0' or '\n'




reply via email to

[Prev in Thread] Current Thread [Next in Thread]