~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

Remove shutil dependency in upgrade - create a delete_tree method for transports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import errno
23
23
from copy import deepcopy
 
24
from stat import *
24
25
import sys
25
26
from unittest import TestSuite
26
27
 
371
372
        """
372
373
        return self._iterate_over(relpaths, self.delete, pb, 'delete', expand=False)
373
374
 
 
375
    def delete_tree(self, relpath):
 
376
        """Delete an entire tree. This may require a listable transport."""
 
377
        subtree = self.clone(relpath)
 
378
        files = []
 
379
        directories = ['.']
 
380
        pending_rmdirs = []
 
381
        while directories:
 
382
            dir = directories.pop()
 
383
            if dir != '.':
 
384
                pending_rmdirs.append(dir)
 
385
            for path in subtree.list_dir(dir):
 
386
                path = dir + '/' + path
 
387
                stat = subtree.stat(path)
 
388
                if S_ISDIR(stat.st_mode):
 
389
                    directories.append(path)
 
390
                else:
 
391
                    files.append(path)
 
392
        subtree.delete_multi(files)
 
393
        pending_rmdirs.reverse()
 
394
        for dir in pending_rmdirs:
 
395
            subtree.rmdir(dir)
 
396
        self.rmdir(relpath)
 
397
 
374
398
    def stat(self, relpath):
375
399
        """Return the stat information for a file.
376
400
        WARNING: This may not be implementable for all protocols, so use
383
407
        """
384
408
        raise NotImplementedError
385
409
 
 
410
    def rmdir(self, relpath):
 
411
        """Remove a directory at the given path."""
 
412
        raise NotImplementedError
 
413
 
386
414
    def stat_multi(self, relpaths, pb=None):
387
415
        """Stat multiple files and return the information.
388
416
        """