Commit ce09f23f authored by bescoto's avatar bescoto

Added reading/writing to chars_to_quote file


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@326 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent 5d4a8ca0
......@@ -55,7 +55,7 @@ class FSAbilities:
self.set_acls(rp)
return self
def init_readwrite(self, rp_base):
def init_readwrite(self, rbdir, use_ctq_file = 1):
"""Set variables using fs tested at rp_base
This method creates a temp directory in rp_base and writes to
......@@ -65,21 +65,57 @@ class FSAbilities:
This sets self.chars_to_quote, self.ownership, self.acls,
self.eas, self.hardlinks, and self.fsync_dirs.
If user_ctq_file is true, try reading the "chars_to_quote"
file in directory.
"""
assert rp_base.isdir()
assert rbdir.isdir()
self.read_only = 0
subdir = TempFile.new_in_dir(rp_base)
subdir = TempFile.new_in_dir(rbdir)
subdir.mkdir()
self.set_ownership(subdir)
self.set_hardlinks(subdir)
self.set_fsync_dirs(subdir)
self.set_chars_to_quote(subdir)
self.set_eas(subdir, 1)
self.set_acls(subdir)
self.set_chars_to_quote(subdir)
if use_ctq_file: self.compare_chars_to_quote(rbdir)
subdir.delete()
return self
def compare_chars_to_quote(self, rbdir):
"""Read chars_to_quote file, compare with current settings"""
assert self.chars_to_quote is not None
ctq_rp = rbdir.append("chars_to_quote")
def write_new_chars():
"""Replace old chars_to_quote file with new value"""
if ctq_rp.lstat(): ctq_rp.delete()
fp = ctq_rp.open("wb")
fp.write(self.chars_to_quote)
assert not fp.close()
def get_old_chars():
fp = ctq_rp.open("rb")
old_chars = fp.read()
assert not fp.close()
return old_chars
if not ctq_rp.lstat(): write_new_chars()
else:
old_chars = get_old_chars()
if old_chars != self.chars_to_quote:
if self.chars_to_quote == "":
log.Log("Warning: File system no longer needs quoting, "
"but will retain for backwards compatibility.", 2)
else: log.FatalError("""New quoting requirements
This may be caused when you copy an rdiff-backup directory from a
normal file system on to a windows one that cannot support the same
characters. If you want to risk it, remove the file
rdiff-backup-data/chars_to_quote.
""")
def set_ownership(self, testdir):
"""Set self.ownership to true iff testdir's ownership can be changed"""
tmp_rp = testdir.append("foo")
......@@ -164,7 +200,7 @@ class FSAbilities:
if supports_unusual_chars(): self.chars_to_quote = ""
else: self.chars_to_quote = "^A-Za-z0-9_ -"
else:
if supports_unusual_chars(): self.chars_to_quote = "A-Z"
if supports_unusual_chars(): self.chars_to_quote = "A-Z;"
else: self.chars_to_quote = "^a-z0-9_ -"
def set_acls(self, rp):
......
import unittest, os
import unittest, os, time
from commontest import *
from rdiff_backup import Globals, rpath, fs_abilities
......@@ -11,7 +11,7 @@ class FSAbilitiesTest(unittest.TestCase):
the expected values below.
"""
# Describes standard linux file system
# Describes standard linux file system with acls/eas
dir_to_test = "testfiles"
eas = acls = 1
chars_to_quote = ""
......@@ -36,7 +36,13 @@ class FSAbilitiesTest(unittest.TestCase):
def testReadWrite(self):
"""Test basic querying read/write"""
base_dir = rpath.RPath(Globals.local_connection, self.dir_to_test)
fsa = fs_abilities.FSAbilities().init_readwrite(base_dir)
new_dir = base_dir.append("fs_abilitiestest")
if new_dir.lstat(): Myrm(new_dir.path)
new_dir.setdata()
new_dir.mkdir()
t = time.time()
fsa = fs_abilities.FSAbilities().init_readwrite(new_dir)
print "Time elapsed = ", time.time() - t
assert fsa.read_only == 0, fsa.read_only
assert fsa.eas == self.eas, fsa.eas
assert fsa.acls == self.acls, fsa.acls
......@@ -45,6 +51,14 @@ class FSAbilitiesTest(unittest.TestCase):
assert fsa.hardlinks == self.hardlinks, fsa.hardlinks
assert fsa.fsync_dirs == self.fsync_dirs, fsa.fsync_dirs
ctq_rp = new_dir.append("chars_to_quote")
assert ctq_rp.lstat()
fp = ctq_rp.open('rb')
chars_to_quote = fp.read()
assert not fp.close()
assert chars_to_quote == self.chars_to_quote, chars_to_quote
new_dir.delete()
if __name__ == "__main__": unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment