/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/transform.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from stat import S_ISREG, S_IEXEC
22
22
import time
23
23
 
24
 
from bzrlib import (
 
24
from . import (
25
25
    config as _mod_config,
26
26
    errors,
27
27
    lazy_import,
30
30
    tree,
31
31
    )
32
32
lazy_import.lazy_import(globals(), """
33
 
from bzrlib import (
 
33
from breezy import (
34
34
    annotate,
35
35
    bencode,
36
36
    controldir,
44
44
    ui,
45
45
    urlutils,
46
46
    )
47
 
from bzrlib.i18n import gettext
 
47
from breezy.i18n import gettext
48
48
""")
49
 
from bzrlib.errors import (DuplicateKey, MalformedTransform,
 
49
from .errors import (DuplicateKey, MalformedTransform,
50
50
                           ReusingTransform, CantMoveRoot,
51
51
                           ImmortalLimbo, NoFinalPath,
52
52
                           UnableCreateSymlink)
53
 
from bzrlib.filters import filtered_output_bytes, ContentFilterContext
54
 
from bzrlib.mutabletree import MutableTree
55
 
from bzrlib.osutils import (
 
53
from .filters import filtered_output_bytes, ContentFilterContext
 
54
from .mutabletree import MutableTree
 
55
from .osutils import (
56
56
    delete_any,
57
57
    file_kind,
58
58
    has_symlinks,
60
60
    sha_file,
61
61
    splitpath,
62
62
    )
63
 
from bzrlib.progress import ProgressPhase
64
 
from bzrlib.symbol_versioning import (
 
63
from .progress import ProgressPhase
 
64
from .symbol_versioning import (
65
65
    deprecated_function,
66
66
    deprecated_in,
67
67
    deprecated_method,
768
768
            if new_executability:
769
769
                umask = os.umask(0)
770
770
                os.umask(umask)
771
 
                to_mode = current_mode | (0100 & ~umask)
 
771
                to_mode = current_mode | (0o100 & ~umask)
772
772
                # Enable x-bit for others only if they can read it.
773
 
                if current_mode & 0004:
774
 
                    to_mode |= 0001 & ~umask
775
 
                if current_mode & 0040:
776
 
                    to_mode |= 0010 & ~umask
 
773
                if current_mode & 0o004:
 
774
                    to_mode |= 0o001 & ~umask
 
775
                if current_mode & 0o040:
 
776
                    to_mode |= 0o010 & ~umask
777
777
            else:
778
 
                to_mode = current_mode & ~0111
 
778
                to_mode = current_mode & ~0o111
779
779
            osutils.chmod_if_possible(abspath, to_mode)
780
780
 
781
781
    def _new_entry(self, name, parent_id, file_id):
1212
1212
            for path in limbo_paths:
1213
1213
                try:
1214
1214
                    delete_any(path)
1215
 
                except OSError, e:
 
1215
                except OSError as e:
1216
1216
                    if e.errno != errno.ENOENT:
1217
1217
                        raise
1218
1218
                    # XXX: warn? perhaps we just got interrupted at an
1350
1350
        name = self._limbo_name(trans_id)
1351
1351
        try:
1352
1352
            os.link(path, name)
1353
 
        except OSError, e:
 
1353
        except OSError as e:
1354
1354
            if e.errno != errno.EPERM:
1355
1355
                raise
1356
1356
            raise errors.HardLinkNotSupported(path)
1619
1619
            return
1620
1620
        try:
1621
1621
            mode = os.stat(self._tree.abspath(old_path)).st_mode
1622
 
        except OSError, e:
 
1622
        except OSError as e:
1623
1623
            if e.errno in (errno.ENOENT, errno.ENOTDIR):
1624
1624
                # Either old_path doesn't exist, or the parent of the
1625
1625
                # target is not a directory (but will be one eventually)
1639
1639
            return
1640
1640
        try:
1641
1641
            children = os.listdir(self._tree.abspath(path))
1642
 
        except OSError, e:
 
1642
        except OSError as e:
1643
1643
            if not (osutils._is_error_enotdir(e)
1644
1644
                    or e.errno in (errno.ENOENT, errno.ESRCH)):
1645
1645
                raise
1836
1836
                      or trans_id in self._new_parent):
1837
1837
                    try:
1838
1838
                        mover.rename(full_path, self._limbo_name(trans_id))
1839
 
                    except errors.TransformRenameFailed, e:
 
1839
                    except errors.TransformRenameFailed as e:
1840
1840
                        if e.errno != errno.ENOENT:
1841
1841
                            raise
1842
1842
                    else:
1867
1867
                if trans_id in self._needs_rename:
1868
1868
                    try:
1869
1869
                        mover.rename(self._limbo_name(trans_id), full_path)
1870
 
                    except errors.TransformRenameFailed, e:
 
1870
                    except errors.TransformRenameFailed as e:
1871
1871
                        # We may be renaming a dangling inventory id
1872
1872
                        if e.errno != errno.ENOENT:
1873
1873
                            raise
2077
2077
    def _has_id(self, file_id, fallback_check):
2078
2078
        if file_id in self._transform._r_new_id:
2079
2079
            return True
2080
 
        elif file_id in set([self._transform.tree_file_id(trans_id) for
2081
 
            trans_id in self._transform._removed_id]):
 
2080
        elif file_id in {self._transform.tree_file_id(trans_id) for
 
2081
            trans_id in self._transform._removed_id}:
2082
2082
            return False
2083
2083
        else:
2084
2084
            return fallback_check(file_id)
2303
2303
        except KeyError:
2304
2304
            try:
2305
2305
                return self._transform._tree.is_executable(file_id, path)
2306
 
            except OSError, e:
 
2306
            except OSError as e:
2307
2307
                if e.errno == errno.ENOENT:
2308
2308
                    return False
2309
2309
                raise
3173
3173
        """Rename a file from one path to another."""
3174
3174
        try:
3175
3175
            os.rename(from_, to)
3176
 
        except OSError, e:
 
3176
        except OSError as e:
3177
3177
            if e.errno in (errno.EEXIST, errno.ENOTEMPTY):
3178
3178
                raise errors.FileExists(to, str(e))
3179
3179
            # normal OSError doesn't include filenames so it's hard to see where
3196
3196
        for from_, to in reversed(self.past_renames):
3197
3197
            try:
3198
3198
                os.rename(to, from_)
3199
 
            except OSError, e:
 
3199
            except OSError as e:
3200
3200
                raise errors.TransformRenameFailed(to, from_, str(e), e.errno)
3201
3201
        # after rollback, don't reuse _FileMover
3202
3202
        past_renames = None