Skip to content

Commit

Permalink
Stop creating extraneous directories
Browse files Browse the repository at this point in the history
Cannot help streamlining the code a bit, sorry. But the meat is that
we should not try to make directories if output path is explicit.

Previously we created directories using the URL path, which is
obviously wrong if explicit output file is supplied... unless
a crafty user supplied the same path with -o that is contained
in the URL path. If anyone was doing such tricks, it's not going
to work anymore (we are forcing a regression for the sake of
theoretical correctness here).

Fixes bug: 1369546

Change-Id: Ifce31f2ba233eb55550f3810348bf16bf2447d62
  • Loading branch information
zaitcev committed Sep 18, 2014
1 parent 45465c7 commit 8f1b394
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions swiftclient/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,18 +1003,18 @@ def _download_object_job(conn, container, obj, options):
fp = None
try:
no_file = options['no_download']
make_dir = not no_file and out_file != "-"
content_type = headers.get('content-type')
if content_type.split(';', 1)[0] == 'text/directory':
make_dir = not no_file and out_file != "-"
if make_dir and not isdir(path):
mkdirs(path)

for _ in obj_body.buffer():
continue
else:
dirpath = dirname(path)
if make_dir and dirpath and not isdir(dirpath):
mkdirs(dirpath)
make_dir = not (no_file or out_file)
if make_dir:
dirpath = dirname(path)
if dirpath and not isdir(dirpath):
mkdirs(dirpath)

if not no_file:
if out_file == "-":
Expand All @@ -1023,30 +1023,25 @@ def _download_object_job(conn, container, obj, options):
'contents': obj_body
}
return res
elif out_file:
if out_file:
fp = open(out_file, 'wb')
else:
if basename(path):
fp = open(path, 'wb')
else:
pseudodir = True
no_file = True

for chunk in obj_body.buffer():
if not no_file:
fp.write(chunk)

else:
for _ in obj_body.buffer():
continue
for chunk in obj_body.buffer():
if fp is not None:
fp.write(chunk)

finish_time = time()

finally:
bytes_read = obj_body.bytes_read()
if fp is not None:
fp.close()
if 'x-object-meta-mtime' in headers \
and not options['no_download']:
if 'x-object-meta-mtime' in headers and not no_file:
mtime = float(headers['x-object-meta-mtime'])
if options['out_file'] \
and not options['out_file'] == "-":
Expand Down

0 comments on commit 8f1b394

Please sign in to comment.