sync: Safely skip already deleted projects

Do not error if a project is missing on the filesystem, is deleted
from manifest.xml, but still exists in project.list.

Change-Id: I1d13e435473c83091e27e4df571504ef493282dd
This commit is contained in:
Anthony 2009-09-26 13:38:52 -04:00 committed by Shawn O. Pearce
parent a1bfd2cd72
commit f3fdf823cf

View File

@ -147,32 +147,36 @@ later is required to fix a server side protocol bug.
if not path: if not path:
continue continue
if path not in new_project_paths: if path not in new_project_paths:
project = Project( """If the path has already been deleted, we don't need to do it
manifest = self.manifest, """
name = path, if os.path.exists(self.manifest.topdir + '/' + path):
remote = RemoteSpec('origin'), project = Project(
gitdir = os.path.join(self.manifest.topdir, manifest = self.manifest,
path, '.git'), name = path,
worktree = os.path.join(self.manifest.topdir, path), remote = RemoteSpec('origin'),
relpath = path, gitdir = os.path.join(self.manifest.topdir,
revisionExpr = 'HEAD', path, '.git'),
revisionId = None) worktree = os.path.join(self.manifest.topdir, path),
if project.IsDirty(): relpath = path,
print >>sys.stderr, 'error: Cannot remove project "%s": \ revisionExpr = 'HEAD',
revisionId = None)
if project.IsDirty():
print >>sys.stderr, 'error: Cannot remove project "%s": \
uncommitted changes are present' % project.relpath uncommitted changes are present' % project.relpath
print >>sys.stderr, ' commit changes, then run sync again' print >>sys.stderr, ' commit changes, then run sync again'
return -1 return -1
else: else:
print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree
shutil.rmtree(project.worktree) shutil.rmtree(project.worktree)
# Try deleting parent subdirs if they are empty # Try deleting parent subdirs if they are empty
dir = os.path.dirname(project.worktree) dir = os.path.dirname(project.worktree)
while dir != self.manifest.topdir: while dir != self.manifest.topdir:
try: try:
os.rmdir(dir) os.rmdir(dir)
except OSError: except OSError:
break break
dir = os.path.dirname(dir) dir = os.path.dirname(dir)
new_project_paths.sort() new_project_paths.sort()
fd = open(file_path, 'w') fd = open(file_path, 'w')