From f3fdf823cf9785e4ceca3e8416b719282d84b6d0 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 26 Sep 2009 13:38:52 -0400 Subject: [PATCH] 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 --- subcmds/sync.py | 54 ++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/subcmds/sync.py b/subcmds/sync.py index deff171a..02dd82df 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -147,32 +147,36 @@ later is required to fix a server side protocol bug. if not path: continue if path not in new_project_paths: - project = Project( - manifest = self.manifest, - name = path, - remote = RemoteSpec('origin'), - gitdir = os.path.join(self.manifest.topdir, - path, '.git'), - worktree = os.path.join(self.manifest.topdir, path), - relpath = path, - revisionExpr = 'HEAD', - revisionId = None) - if project.IsDirty(): - print >>sys.stderr, 'error: Cannot remove project "%s": \ + """If the path has already been deleted, we don't need to do it + """ + if os.path.exists(self.manifest.topdir + '/' + path): + project = Project( + manifest = self.manifest, + name = path, + remote = RemoteSpec('origin'), + gitdir = os.path.join(self.manifest.topdir, + path, '.git'), + worktree = os.path.join(self.manifest.topdir, path), + relpath = path, + revisionExpr = 'HEAD', + revisionId = None) + + if project.IsDirty(): + print >>sys.stderr, 'error: Cannot remove project "%s": \ uncommitted changes are present' % project.relpath - print >>sys.stderr, ' commit changes, then run sync again' - return -1 - else: - print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree - shutil.rmtree(project.worktree) - # Try deleting parent subdirs if they are empty - dir = os.path.dirname(project.worktree) - while dir != self.manifest.topdir: - try: - os.rmdir(dir) - except OSError: - break - dir = os.path.dirname(dir) + print >>sys.stderr, ' commit changes, then run sync again' + return -1 + else: + print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree + shutil.rmtree(project.worktree) + # Try deleting parent subdirs if they are empty + dir = os.path.dirname(project.worktree) + while dir != self.manifest.topdir: + try: + os.rmdir(dir) + except OSError: + break + dir = os.path.dirname(dir) new_project_paths.sort() fd = open(file_path, 'w')