From: Daira Hopwood Date: Tue, 11 Aug 2015 16:02:53 +0000 (+0100) Subject: Use get_pathinfo instead of separate os.path.{is*,exists} calls. X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/provisioning?a=commitdiff_plain;h=49444fabd0d3c2d404438f635d2506e7a743bb18;p=tahoe-lafs%2Ftahoe-lafs.git Use get_pathinfo instead of separate os.path.{is*,exists} calls. Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index 15d1262f..4a4db449 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -12,7 +12,7 @@ from twisted.application import service from allmydata.util import fileutil from allmydata.interfaces import IDirectoryNode from allmydata.util import log -from allmydata.util.fileutil import precondition_abspath +from allmydata.util.fileutil import precondition_abspath, get_pathinfo from allmydata.util.assertutil import precondition from allmydata.util.encodingutil import listdir_unicode, to_filepath, \ @@ -240,21 +240,18 @@ class Uploader(QueueMixin): def _process_child(self, path_u): precondition(isinstance(path_u, unicode), path_u) - # note: symlinks to directories are both islink() and isdir() - isdir = os.path.isdir(path_u) - isfile = os.path.isfile(path_u) - islink = os.path.islink(path_u) + pathinfo = get_pathinfo(path_u) - if islink: + if pathinfo.islink: self.warn("WARNING: cannot backup symlink %s" % quote_local_unicode_path(path_u)) return None - elif isdir: + elif pathinfo.isdir: # process directories unconditionally self._append_to_deque(path_u) # recurse on the child directory return self._scan(path_u) - elif isfile: + elif pathinfo.isfile: file_version = self._db.get_local_file_version(path_u) if file_version is None: # XXX upload if we didn't record our version in magicfolder db? @@ -285,13 +282,17 @@ class Uploader(QueueMixin): def _process(self, path_u): precondition(isinstance(path_u, unicode), path_u) + d = defer.succeed(None) def _maybe_upload(val): + pathinfo = get_pathinfo(path_u) + self._pending.remove(path_u) # FIXME make _upload_pending hold relative paths relpath_u = os.path.relpath(path_u, self._local_path_u) encoded_name_u = magicpath.path2magic(relpath_u) - if not os.path.exists(path_u): + + if not pathinfo.exists: self._log("drop-upload: notified object %r disappeared " "(this is normal for temporary objects)" % (path_u,)) self._count('objects_disappeared') @@ -319,12 +320,12 @@ class Uploader(QueueMixin): d2.addCallback(lambda x: self._get_filenode(encoded_name_u)) d2.addCallback(add_db_entry) - d2.addCallback(lambda x: Exception("file does not exist")) + d2.addCallback(lambda x: Exception("file does not exist")) # FIXME wrong return d2 - elif os.path.islink(path_u): + elif pathinfo.islink: self.warn("WARNING: cannot upload symlink %s" % quote_local_unicode_path(path_u)) return None - elif os.path.isdir(path_u): + elif pathinfo.isdir: self._notifier.watch(to_filepath(path_u), mask=self.mask, callbacks=[self._notify], recursive=True) uploadable = Data("", self._client.convergence) encoded_name_u += u"@_" @@ -338,7 +339,7 @@ class Uploader(QueueMixin): upload_d.addCallbacks(_succeeded, _failed) upload_d.addCallback(lambda ign: self._scan(path_u)) return upload_d - elif os.path.isfile(path_u): + elif pathinfo.isfile: version = self._db.get_local_file_version(relpath_u) if version is None: version = 0 @@ -349,11 +350,9 @@ class Uploader(QueueMixin): d2 = self._upload_dirnode.add_file(encoded_name_u, uploadable, metadata={"version":version}, overwrite=True) def add_db_entry(filenode): filecap = filenode.get_uri() - s = os.stat(path_u) - size = s[stat.ST_SIZE] - ctime = s[stat.ST_CTIME] - mtime = s[stat.ST_MTIME] - self._db.did_upload_file(filecap, relpath_u, version, mtime, ctime, size) + # XXX maybe just pass pathinfo + self._db.did_upload_file(filecap, relpath_u, version, + pathinfo.mtime, pathinfo.ctime, pathinfo.size) self._count('files_uploaded') d2.addCallback(add_db_entry) return d2 diff --git a/src/allmydata/util/fileutil.py b/src/allmydata/util/fileutil.py index 97ef09b7..9a194e99 100644 --- a/src/allmydata/util/fileutil.py +++ b/src/allmydata/util/fileutil.py @@ -641,7 +641,7 @@ def get_pathinfo(path_u): ) except OSError as e: if e.errno == ENOENT: - return PathInfo(isdir=False, + return PathInfo(isdir =False, isfile=False, islink=False, exists=False,