From ede51f117aa47e757d65695ff0764aa0052c2e59 Mon Sep 17 00:00:00 2001 From: JoeLametta Date: Sun, 29 Nov 2015 16:20:49 +0100 Subject: [PATCH] encode to final path+'.part' instead of a temp file thomasvs/morituri#109 --- morituri/program/cdparanoia.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/morituri/program/cdparanoia.py b/morituri/program/cdparanoia.py index 46176d5..55909c1 100644 --- a/morituri/program/cdparanoia.py +++ b/morituri/program/cdparanoia.py @@ -445,7 +445,6 @@ class ReadVerifyTrackTask(log.Loggable, task.MultiSeparateTask): task.MultiSeparateTask.__init__(self) self.debug('Creating read and verify task on %r', path) - self.path = path if taglist: self.debug('read and verify with taglist %r', taglist) @@ -468,11 +467,18 @@ class ReadVerifyTrackTask(log.Loggable, task.MultiSeparateTask): self.tasks.append(t) self.tasks.append(checksum.CRC32Task(tmppath)) - fd, tmpoutpath = tempfile.mkstemp(suffix='.morituri.%s' % - profile.extension) - tmpoutpath = unicode(tmpoutpath) - os.close(fd) + # encode to the final path + '.part' + try: + tmpoutpath = path + u'.part' + open(tmpoutpath, 'wb').close() + except IOError, e: + if errno.ENAMETOOLONG != e.errno: + raise + path = common.shrinkPath(path) + tmpoutpath = path + u'.part' + open(tmpoutpath, 'wb').close() self._tmppath = tmpoutpath + self.path = path # here to avoid import gst eating our options from morituri.common import encode @@ -484,10 +490,6 @@ class ReadVerifyTrackTask(log.Loggable, task.MultiSeparateTask): self.checksum = None - umask = os.umask(0) - os.umask(umask) - self.file_mode = 0666 - umask - def stop(self): # FIXME: maybe this kind of try-wrapping to make sure # we chain up should be handled by a parent class function ? @@ -521,16 +523,10 @@ class ReadVerifyTrackTask(log.Loggable, task.MultiSeparateTask): # delete the unencoded file os.unlink(self._tmpwavpath) - os.chmod(self._tmppath, self.file_mode) - if not self.exception: try: self.debug('Moving to final path %r', self.path) - shutil.move(self._tmppath, self.path) - except IOError, e: - if e.errno == errno.ENAMETOOLONG: - self.path = common.shrinkPath(self.path) - shutil.move(self._tmppath, self.path) + os.rename(self._tmppath, self.path) except Exception, e: self.debug('Exception while moving to final path %r: ' '%r',