Skip to content

Commit 9f339c9

Browse files
committed
Don't delete temp directory in fetch_via_vcs
Signed-off-by: Tushar Goel <[email protected]>
1 parent cbe8edb commit 9f339c9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/fetchcode/vcs/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations under the License.
1616

1717
import os
18+
import shutil
1819
import tempfile
1920
from urllib.parse import urlparse
2021

@@ -38,6 +39,14 @@ def __init__(self, dest_dir, vcs_type, domain):
3839
self.dest_dir = dest_dir
3940
self.vcs_type = vcs_type
4041
self.domain = domain
42+
43+
44+
def delete(self):
45+
"""
46+
Delete the temporary directory.
47+
"""
48+
if os.path.isdir(self.dest_dir):
49+
shutil.rmtree(path=self.dest_dir)
4150

4251

4352
def fetch_via_vcs(url):
@@ -48,8 +57,7 @@ def fetch_via_vcs(url):
4857
parsed_url = urlparse(url)
4958
scheme = parsed_url.scheme
5059
domain = parsed_url.netloc
51-
temp = tempfile.mkdtemp()
52-
os.rmdir(temp)
60+
dest_dir = os.path.join(tempfile.mkdtemp(), "checkout")
5361
if scheme not in vcs.all_schemes:
5462
raise Exception("Not a supported/known scheme.")
5563

@@ -58,6 +66,6 @@ def fetch_via_vcs(url):
5866
vcs_type = vcs_name
5967

6068
backend = vcs.get_backend_for_scheme(scheme)
61-
backend.obtain(dest=temp, url=misc.hide_url(url))
69+
backend.obtain(dest=dest_dir, url=misc.hide_url(url))
6270

63-
return VCSResponse(dest_dir=temp, vcs_type=vcs_type, domain=domain)
71+
return VCSResponse(dest_dir=dest_dir, vcs_type=vcs_type, domain=domain)

0 commit comments

Comments
 (0)