Skip to content

Commit

Permalink
another try when file doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
kalefranz committed Nov 16, 2016
1 parent 0b50ebd commit e196194
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions conda/gateways/adapters/localfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from logging import getLogger
from mimetypes import guess_type
from os import lstat
from os.path import isfile
from requests.adapters import BaseAdapter
from requests.models import Response
from requests.structures import CaseInsensitiveDict
Expand All @@ -29,17 +30,20 @@ def send(self, request, stream=None, timeout=None, verify=None, cert=None, proxi
resp.status_code = 404
resp.raw = exc
else:
modified = formatdate(stats.st_mtime, usegmt=True)
content_type = guess_type(pathname)[0] or "text/plain"
resp.headers = CaseInsensitiveDict({
"Content-Type": content_type,
"Content-Length": stats.st_size,
"Last-Modified": modified,
})

resp.raw = open(pathname, "rb")
resp.close = resp.raw.close

if isfile(pathname):
modified = formatdate(stats.st_mtime, usegmt=True)
content_type = guess_type(pathname)[0] or "text/plain"
resp.headers = CaseInsensitiveDict({
"Content-Type": content_type,
"Content-Length": stats.st_size,
"Last-Modified": modified,
})

resp.raw = open(pathname, "rb")
resp.close = resp.raw.close
else:
resp.status_code = 404
resp.raw = b'{"error": "file does not exist", "path": "%s"}' % pathname
return resp

def close(self):
Expand Down

0 comments on commit e196194

Please sign in to comment.