Skip to content

Commit

Permalink
Merge branch meejah/2814.concurrent-magicfolder-writes.0
Browse files Browse the repository at this point in the history
  • Loading branch information
warner committed Aug 31, 2016
2 parents cb35473 + 0466522 commit 0670144
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/allmydata/frontends/magic_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,13 @@ def stop(self):
d.addCallback(lambda ign: self._processing)
return d

def _should_download(self, relpath_u, remote_version):
def _should_download(self, relpath_u, remote_version, remote_uri):
"""
_should_download returns a bool indicating whether or not a remote object should be downloaded.
We check the remote metadata version against our magic-folder db version number;
latest version wins.
"""
self._log("_should_download(%r, %r)" % (relpath_u, remote_version))
self._log("_should_download(%r, %r, %r)" % (relpath_u, remote_version, remote_uri))
if magicpath.should_ignore_file(relpath_u):
self._log("nope")
return False
Expand All @@ -800,18 +800,21 @@ def _should_download(self, relpath_u, remote_version):
if db_entry is None:
return True
self._log("version %r" % (db_entry.version,))
return (db_entry.version < remote_version)
if db_entry.version < remote_version:
return True
if db_entry.last_downloaded_uri != remote_uri:
return True
return False

def _get_local_latest(self, relpath_u):
"""
_get_local_latest takes a unicode path string checks to see if this file object
exists in our magic-folder db; if not then return None
else check for an entry in our magic-folder db and return the version number.
else check for an entry in our magic-folder db and return it.
"""
if not self._get_filepath(relpath_u).exists():
return None
db_entry = self._db.get_db_entry(relpath_u)
return None if db_entry is None else db_entry.version
return self._db.get_db_entry(relpath_u)

def _get_collective_latest_file(self, filename):
"""
Expand Down Expand Up @@ -853,11 +856,19 @@ def scan_listing(listing_map):
self._log("found %r" % (relpath_u,))

file_node, metadata = listing_map[encoded_relpath_u]
local_version = self._get_local_latest(relpath_u)
local_dbentry = self._get_local_latest(relpath_u)

# XXX FIXME this is *awefully* similar to
# _should_download code in function etc -- can we
# share?
remote_version = metadata.get('version', None)
self._log("%r has local version %r, remote version %r" % (relpath_u, local_version, remote_version))
remote_uri = file_node.get_readonly_uri()
self._log("%r has local dbentry %r, remote version %r, remote uri %r"
% (relpath_u, local_dbentry, remote_version, remote_uri))

if local_version is None or remote_version is None or local_version < remote_version:
if (local_dbentry is None or remote_version is None or
local_dbentry.version < remote_version or
(local_dbentry.version == remote_version and local_dbentry.last_downloaded_uri != remote_uri)):
self._log("%r added to download queue" % (relpath_u,))
if scan_batch.has_key(relpath_u):
scan_batch[relpath_u] += [(file_node, metadata)]
Expand Down Expand Up @@ -897,7 +908,7 @@ def _filter_batch_to_deque(ign):
for relpath_u in scan_batch.keys():
file_node, metadata = max(scan_batch[relpath_u], key=lambda x: x[1]['version'])

if self._should_download(relpath_u, metadata['version']):
if self._should_download(relpath_u, metadata['version'], file_node.get_readonly_uri()):
to_dl = DownloadItem(
relpath_u,
PercentProgress(file_node.get_size()),
Expand Down

0 comments on commit 0670144

Please sign in to comment.