Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't delete temp directory in fetch_via_vcs #78

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/fetchcode/vcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations under the License.

import os
import shutil
import tempfile
from urllib.parse import urlparse

Expand All @@ -28,28 +29,34 @@

class VCSResponse:
"""
Represent the response from fetching a VCS URL with:
- `dest_dir`: destination of directory
- `vcs_type`: VCS Type of URL (git,bzr,hg,svn)
- `domain` : Source of git VCS (GitHub, Gitlab, Bitbucket)
Represent the response from fetching a VCS URL with:
- `dest_dir`: destination of directory
- `vcs_type`: VCS Type of URL (git,bzr,hg,svn)
- `domain` : Source of git VCS (GitHub, Gitlab, Bitbucket)
"""

def __init__(self, dest_dir, vcs_type, domain):
self.dest_dir = dest_dir
self.vcs_type = vcs_type
self.domain = domain

def delete(self):
"""
Delete the temporary directory.
"""
if os.path.isdir(self.dest_dir):
shutil.rmtree(path=self.dest_dir)


def fetch_via_vcs(url):
"""
Take `url` as input and store the content of it at location specified at `location` string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no location arg here? Why create a temp directory and not accept instead a proper location?

Return a VCSResponse object
Return a VCSResponse object
"""
parsed_url = urlparse(url)
scheme = parsed_url.scheme
domain = parsed_url.netloc
temp = tempfile.mkdtemp()
os.rmdir(temp)
dest_dir = os.path.join(tempfile.mkdtemp(), "checkout")
if scheme not in vcs.all_schemes:
raise Exception("Not a supported/known scheme.")

Expand All @@ -58,6 +65,6 @@ def fetch_via_vcs(url):
vcs_type = vcs_name

backend = vcs.get_backend_for_scheme(scheme)
backend.obtain(dest=temp, url=misc.hide_url(url))
backend.obtain(dest=dest_dir, url=misc.hide_url(url))

return VCSResponse(dest_dir=temp, vcs_type=vcs_type, domain=domain)
return VCSResponse(dest_dir=dest_dir, vcs_type=vcs_type, domain=domain)