/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2007-09-24 15:01:26 UTC
  • mfrom: (2853 +trunk)
  • mto: (2885.1.1 140432)
  • mto: This revision was merged to the branch mainline in revision 2886.
  • Revision ID: v.ladeuil+lp@free.fr-20070924150126-nll7i0385kisklyj
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
        os.chmod(filename, mod)
88
88
 
89
89
 
 
90
def minimum_path_selection(paths):
 
91
    """Return the smallset subset of paths which are outside paths.
 
92
 
 
93
    :param paths: A container (and hence not None) of paths.
 
94
    :return: A set of paths sufficient to include everything in paths via
 
95
        is_inside_any, drawn from the paths parameter.
 
96
    """
 
97
    search_paths = set()
 
98
    paths = set(paths)
 
99
    for path in paths:
 
100
        other_paths = paths.difference([path])
 
101
        if not is_inside_any(other_paths, path):
 
102
            # this is a top level path, we must check it.
 
103
            search_paths.add(path)
 
104
    return search_paths
 
105
 
 
106
 
90
107
_QUOTE_RE = None
91
108
 
92
109
 
567
584
    return s.hexdigest()
568
585
 
569
586
 
570
 
 
571
 
def sha_strings(strings):
 
587
def sha_strings(strings, _factory=sha.new):
572
588
    """Return the sha-1 of concatenation of strings"""
573
 
    s = sha.new()
 
589
    s = _factory()
574
590
    map(s.update, strings)
575
591
    return s.hexdigest()
576
592
 
577
593
 
578
 
def sha_string(f):
579
 
    s = sha.new()
580
 
    s.update(f)
581
 
    return s.hexdigest()
 
594
def sha_string(f, _factory=sha.new):
 
595
    return _factory(f).hexdigest()
582
596
 
583
597
 
584
598
def fingerprint_file(f):
585
 
    s = sha.new()
586
599
    b = f.read()
587
 
    s.update(b)
588
 
    size = len(b)
589
 
    return {'size': size,
590
 
            'sha1': s.hexdigest()}
 
600
    return {'size': len(b),
 
601
            'sha1': sha.new(b).hexdigest()}
591
602
 
592
603
 
593
604
def compare_files(a, b):
792
803
            raise
793
804
        shutil.copyfile(src, dest)
794
805
 
795
 
def delete_any(full_path):
 
806
 
 
807
# Look Before You Leap (LBYL) is appropriate here instead of Easier to Ask for
 
808
# Forgiveness than Permission (EAFP) because:
 
809
# - root can damage a solaris file system by using unlink,
 
810
# - unlink raises different exceptions on different OSes (linux: EISDIR, win32:
 
811
#   EACCES, OSX: EPERM) when invoked on a directory.
 
812
def delete_any(path):
796
813
    """Delete a file or directory."""
797
 
    try:
798
 
        os.unlink(full_path)
799
 
    except OSError, e:
800
 
    # We may be renaming a dangling inventory id
801
 
        if e.errno not in (errno.EISDIR, errno.EACCES, errno.EPERM):
802
 
            raise
803
 
        os.rmdir(full_path)
 
814
    if isdir(path): # Takes care of symlinks
 
815
        os.rmdir(path)
 
816
    else:
 
817
        os.unlink(path)
804
818
 
805
819
 
806
820
def has_symlinks():
808
822
        return True
809
823
    else:
810
824
        return False
811
 
        
 
825
 
812
826
 
813
827
def contains_whitespace(s):
814
828
    """True if there are any whitespace characters in s."""