From 40a5c752de62dd1b3ef3ec0850f1f24e7af67052 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Fri, 11 Jul 2014 17:37:54 +0000 Subject: Allow non-unicode paths to be hardlinked into staging areas Parts of the morphology go into the name of the staging area, so it helps to convert them into a str, so later attempts to join it with another string don't result in a unicode string. pyfilesystem insists that file paths must be unicode. It is incorrect, but we passed something unicode compatible in in the first place, so we can get away with converting it back to a bytestring. --- morphlib/artifact.py | 10 +++++----- morphlib/localartifactcache.py | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/morphlib/artifact.py b/morphlib/artifact.py index 20fdb185..da6d3763 100644 --- a/morphlib/artifact.py +++ b/morphlib/artifact.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012, 2013 Codethink Limited +# Copyright (C) 2012, 2013, 2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -56,13 +56,13 @@ class Artifact(object): def basename(self): # pragma: no cover return '%s.%s.%s' % (self.cache_key, - self.source.morphology['kind'], - self.name) + str(self.source.morphology['kind']), + str(self.name)) def metadata_basename(self, metadata_name): # pragma: no cover return '%s.%s.%s.%s' % (self.cache_key, - self.source.morphology['kind'], - self.name, + str(self.source.morphology['kind']), + str(self.name), metadata_name) def get_dependency_prefix_set(self): diff --git a/morphlib/localartifactcache.py b/morphlib/localartifactcache.py index 4c7f7832..955ee97f 100644 --- a/morphlib/localartifactcache.py +++ b/morphlib/localartifactcache.py @@ -96,14 +96,23 @@ class LocalArtifactCache(object): os.utime(filename, None) return open(filename) + def _join(self, basename): + '''Wrapper for pyfilesystem's getsyspath. + + This is required because its API throws us a garbage unicode + string, when file paths are binary data. + ''' + return str(self.cachefs.getsyspath(basename)) + def artifact_filename(self, artifact): - return self.cachefs.getsyspath(artifact.basename()) + basename = artifact.basename() + return self._join(basename) def _artifact_metadata_filename(self, artifact, name): - return self.cachefs.getsyspath(artifact.metadata_basename(name)) + return self._join(artifact.metadata_basename(name)) def _source_metadata_filename(self, source, cachekey, name): - return self.cachefs.getsyspath('%s.%s' % (cachekey, name)) + return self._join('%s.%s' % (cachekey, name)) def clear(self): '''Clear everything from the artifact cache directory. -- cgit v1.2.1