~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-06-01 10:00:41 UTC
  • mfrom: (5946.1.3 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20110601100041-xxi0zwzza9z4oz64
(gz) Handle bug #597686, if we open() try to delete the file,
        even if there was an error.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1172
1172
        if self._tree is None:
1173
1173
            return
1174
1174
        try:
1175
 
            entries = [(self._limbo_name(t), t, k) for t, k in
1176
 
                       self._new_contents.iteritems()]
1177
 
            entries.sort(reverse=True)
1178
 
            for path, trans_id, kind in entries:
1179
 
                delete_any(path)
 
1175
            limbo_paths = sorted(self._limbo_files.values(), reverse=True)
 
1176
            for path in limbo_paths:
 
1177
                try:
 
1178
                    delete_any(path)
 
1179
                except OSError, e:
 
1180
                    if e.errno != errno.ENOENT:
 
1181
                        raise
 
1182
                    # XXX: warn? perhaps we just got interrupted at an
 
1183
                    # inconvenient moment, but perhaps files are disappearing
 
1184
                    # from under us?
1180
1185
            try:
1181
1186
                delete_any(self._limbodir)
1182
1187
            except OSError:
1265
1270
        name = self._limbo_name(trans_id)
1266
1271
        f = open(name, 'wb')
1267
1272
        try:
1268
 
            try:
1269
 
                unique_add(self._new_contents, trans_id, 'file')
1270
 
            except:
1271
 
                # Clean up the file, it never got registered so
1272
 
                # TreeTransform.finalize() won't clean it up.
1273
 
                f.close()
1274
 
                os.unlink(name)
1275
 
                raise
 
1273
            unique_add(self._new_contents, trans_id, 'file')
1276
1274
            f.writelines(contents)
1277
1275
        finally:
1278
1276
            f.close()
1851
1849
                    self._observed_sha1s[trans_id] = (o_sha1, st)
1852
1850
        finally:
1853
1851
            child_pb.finished()
 
1852
        for path, trans_id in new_paths:
 
1853
            # new_paths includes stuff like workingtree conflicts. Only the
 
1854
            # stuff in new_contents actually comes from limbo.
 
1855
            if trans_id in self._limbo_files:
 
1856
                del self._limbo_files[trans_id]
1854
1857
        self._new_contents.clear()
1855
1858
        return modified_paths
1856
1859