[llvm] r355896 - Fix git-llvm crashing when trying to remove directory while cleaning

Raphael Isemann via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 00:40:55 PDT 2019


Author: teemperor
Date: Tue Mar 12 00:40:54 2019
New Revision: 355896

URL: http://llvm.org/viewvc/llvm-project?rev=355896&view=rev
Log:
Fix git-llvm crashing when trying to remove directory while cleaning

Summary:
I'm trying to push D59198 but it seems that `git-llvm push` can't handle the fact
that I add a new directory in the patch:

```
> git llvm push -n
Pushing 1 commit:
  e7c0a9bd136 Correctly look up declarations in inline namespaces
Traceback (most recent call last):
  File "llvm/utils/git-svn//git-llvm", line 431, in <module>
    args.func(args)
  File "llvm/utils/git-svn//git-llvm", line 385, in cmd_push
    clean_svn(svn_root)
  File "llvm/utils/git-svn//git-llvm", line 201, in clean_svn
    os.remove(os.path.join(svn_repo, filename))
IsADirectoryError: [Errno 21] Is a directory: '.git/llvm-upstream-svn/lldb/trunk/packages/Python/lldbsuite/test/expression_command/inline-namespace'
```

This patch just uses shutil to delete the directory instead of trying to use `os.remove`
which only works for files.

Reviewers: mehdi_amini, jlebar

Reviewed By: jlebar

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59236

Modified:
    llvm/trunk/utils/git-svn/git-llvm

Modified: llvm/trunk/utils/git-svn/git-llvm
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/git-svn/git-llvm?rev=355896&r1=355895&r2=355896&view=diff
==============================================================================
--- llvm/trunk/utils/git-svn/git-llvm (original)
+++ llvm/trunk/utils/git-svn/git-llvm Tue Mar 12 00:40:54 2019
@@ -22,6 +22,7 @@ import contextlib
 import errno
 import os
 import re
+import shutil
 import subprocess
 import sys
 import tempfile
@@ -198,7 +199,18 @@ def clean_svn(svn_repo):
         if not line.startswith('?'):
             continue
         filename = line[1:].strip()
-        os.remove(os.path.join(svn_repo, filename))
+        filepath = os.path.abspath(os.path.join(svn_repo, filename))
+        abs_svn_repo = os.path.abspath(svn_repo)
+        # Safety check that the directory we are about to delete is
+        # actually within our svn staging dir.
+        if not filepath.startswith(abs_svn_repo):
+            die("Path to clean (%s) is not in svn staging dir (%s)"
+                % (filepath, abs_svn_repo))
+
+        if os.path.isdir(filepath):
+            shutil.rmtree(filepath)
+        else:
+            os.remove(filepath)
 
 
 def svn_init(svn_root):




More information about the llvm-commits mailing list