diff options
author | Josip Sokcevic <sokcevic@google.com> | 2024-01-24 13:54:25 -0800 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-01-25 21:32:58 +0000 |
commit | 4217a82bec7b95c1a0bc7b081a1764a6a6d6c59b (patch) | |
tree | 97b55aa04e1d2e3692b212d9e7438728c86a8423 /project.py | |
parent | 208f34495086eba60f744408aa26b4c62d6db6c6 (diff) | |
download | git-repo-4217a82bec7b95c1a0bc7b081a1764a6a6d6c59b.tar.gz |
project: Rename if deletion failsv2.41
If a project contains files not owned by the current user, remove will
fail. In order to ensure repo sync continues to work, rename the
affected project instead, and let user know about it.
Bug: 321273512
Change-Id: I0779d61fc67042308a0226adea7d98167252a5d3
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/404372
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -1848,7 +1848,7 @@ class Project: | |||
1848 | platform_utils.remove(path) | 1848 | platform_utils.remove(path) |
1849 | except OSError as e: | 1849 | except OSError as e: |
1850 | if e.errno != errno.ENOENT: | 1850 | if e.errno != errno.ENOENT: |
1851 | logger.error("error: %s: Failed to remove: %s", path, e) | 1851 | logger.warning("%s: Failed to remove: %s", path, e) |
1852 | failed = True | 1852 | failed = True |
1853 | errors.append(e) | 1853 | errors.append(e) |
1854 | dirs[:] = [ | 1854 | dirs[:] = [ |
@@ -1867,7 +1867,7 @@ class Project: | |||
1867 | platform_utils.remove(d) | 1867 | platform_utils.remove(d) |
1868 | except OSError as e: | 1868 | except OSError as e: |
1869 | if e.errno != errno.ENOENT: | 1869 | if e.errno != errno.ENOENT: |
1870 | logger.error("error: %s: Failed to remove: %s", d, e) | 1870 | logger.warning("%s: Failed to remove: %s", d, e) |
1871 | failed = True | 1871 | failed = True |
1872 | errors.append(e) | 1872 | errors.append(e) |
1873 | elif not platform_utils.listdir(d): | 1873 | elif not platform_utils.listdir(d): |
@@ -1875,18 +1875,30 @@ class Project: | |||
1875 | platform_utils.rmdir(d) | 1875 | platform_utils.rmdir(d) |
1876 | except OSError as e: | 1876 | except OSError as e: |
1877 | if e.errno != errno.ENOENT: | 1877 | if e.errno != errno.ENOENT: |
1878 | logger.error("error: %s: Failed to remove: %s", d, e) | 1878 | logger.warning("%s: Failed to remove: %s", d, e) |
1879 | failed = True | 1879 | failed = True |
1880 | errors.append(e) | 1880 | errors.append(e) |
1881 | if failed: | 1881 | if failed: |
1882 | logger.error( | 1882 | rename_path = ( |
1883 | "error: %s: Failed to delete obsolete checkout.", | 1883 | f"{self.worktree}_repo_to_be_deleted_{int(time.time())}" |
1884 | self.RelPath(local=False), | ||
1885 | ) | 1884 | ) |
1886 | logger.error( | 1885 | try: |
1887 | " Remove manually, then run `repo sync -l`.", | 1886 | platform_utils.rename(self.worktree, rename_path) |
1888 | ) | 1887 | logger.warning( |
1889 | raise DeleteWorktreeError(aggregate_errors=errors) | 1888 | "warning: renamed %s to %s. You can delete it, but you " |
1889 | "might need elevated permissions (e.g. root)", | ||
1890 | self.worktree, | ||
1891 | rename_path, | ||
1892 | ) | ||
1893 | # Rename successful! Clear the errors. | ||
1894 | errors = [] | ||
1895 | except OSError: | ||
1896 | logger.error( | ||
1897 | "%s: Failed to delete obsolete checkout.\n", | ||
1898 | " Remove manually, then run `repo sync -l`.", | ||
1899 | self.RelPath(local=False), | ||
1900 | ) | ||
1901 | raise DeleteWorktreeError(aggregate_errors=errors) | ||
1890 | 1902 | ||
1891 | # Try deleting parent dirs if they are empty. | 1903 | # Try deleting parent dirs if they are empty. |
1892 | path = self.worktree | 1904 | path = self.worktree |