[svn r37779] Fix and a test for disappearing files.
--HG-- branch : trunk
This commit is contained in:
parent
23aeccc8c8
commit
cf7e2d7c28
|
@ -85,16 +85,23 @@ class RSync(object):
|
||||||
elif command == "send":
|
elif command == "send":
|
||||||
modified_rel_path, checksum = data
|
modified_rel_path, checksum = data
|
||||||
modifiedpath = os.path.join(self.sourcedir, *modified_rel_path)
|
modifiedpath = os.path.join(self.sourcedir, *modified_rel_path)
|
||||||
|
try:
|
||||||
f = open(modifiedpath, 'rb')
|
f = open(modifiedpath, 'rb')
|
||||||
data = f.read()
|
data = f.read()
|
||||||
|
except IOError:
|
||||||
|
data = None
|
||||||
|
|
||||||
# provide info to progress callback function
|
# provide info to progress callback function
|
||||||
modified_rel_path = "/".join(modified_rel_path)
|
modified_rel_path = "/".join(modified_rel_path)
|
||||||
|
if data is not None:
|
||||||
self.paths[modified_rel_path] = len(data)
|
self.paths[modified_rel_path] = len(data)
|
||||||
|
else:
|
||||||
|
self.paths[modified_rel_path] = 0
|
||||||
if channel not in self.to_send:
|
if channel not in self.to_send:
|
||||||
self.to_send[channel] = []
|
self.to_send[channel] = []
|
||||||
self.to_send[channel].append(modified_rel_path)
|
self.to_send[channel].append(modified_rel_path)
|
||||||
|
|
||||||
|
if data is not None:
|
||||||
f.close()
|
f.close()
|
||||||
if checksum is not None and checksum == md5.md5(data).digest():
|
if checksum is not None and checksum == md5.md5(data).digest():
|
||||||
data = None # not really modified
|
data = None # not really modified
|
||||||
|
@ -118,7 +125,11 @@ class RSync(object):
|
||||||
self.links.append(("link", basename, linkpoint))
|
self.links.append(("link", basename, linkpoint))
|
||||||
|
|
||||||
def _send_directory_structure(self, path):
|
def _send_directory_structure(self, path):
|
||||||
|
try:
|
||||||
st = os.lstat(path)
|
st = os.lstat(path)
|
||||||
|
except OSError:
|
||||||
|
self._broadcast((0, 0))
|
||||||
|
return
|
||||||
if stat.S_ISREG(st.st_mode):
|
if stat.S_ISREG(st.st_mode):
|
||||||
# regular file: send a timestamp/size pair
|
# regular file: send a timestamp/size pair
|
||||||
self._broadcast((st.st_mtime, st.st_size))
|
self._broadcast((st.st_mtime, st.st_size))
|
||||||
|
|
|
@ -65,7 +65,10 @@ def f():
|
||||||
f = open(path, 'wb')
|
f = open(path, 'wb')
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
f.close()
|
||||||
|
try:
|
||||||
os.utime(path, (time, time))
|
os.utime(path, (time, time))
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
del data
|
del data
|
||||||
channel.send(("links", None))
|
channel.send(("links", None))
|
||||||
|
|
||||||
|
|
|
@ -78,3 +78,24 @@ def test_callback():
|
||||||
|
|
||||||
assert total == {("list", 110):True, ("ack", 100):True, ("ack", 10):True}
|
assert total == {("list", 110):True, ("ack", 100):True, ("ack", 10):True}
|
||||||
|
|
||||||
|
def test_file_disappearing():
|
||||||
|
base = py.test.ensuretemp("file_disappearing")
|
||||||
|
dest = base.join("dest")
|
||||||
|
source = base.join("source")
|
||||||
|
source.ensure("ex").write("a" * 100)
|
||||||
|
source.ensure("ex2").write("a" * 100)
|
||||||
|
|
||||||
|
class DRsync(RSync):
|
||||||
|
def filter(self, x):
|
||||||
|
if x.endswith("ex2"):
|
||||||
|
self.x = 1
|
||||||
|
source.join("ex2").remove()
|
||||||
|
return True
|
||||||
|
|
||||||
|
rsync = DRsync()
|
||||||
|
rsync.add_target(gw, dest)
|
||||||
|
rsync.send(source)
|
||||||
|
assert rsync.x == 1
|
||||||
|
assert len(dest.listdir()) == 1
|
||||||
|
assert len(source.listdir()) == 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue