Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Commit

Permalink
1.5.2: Chunked file uploads (which actually work)
Browse files Browse the repository at this point in the history
  • Loading branch information
divad committed Sep 28, 2016
1 parent 4b4bf3a commit b872040
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bargate/defaultcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from datetime import timedelta

## Bargate version number
VERSION='1.5.1'
VERSION='1.5.2'

## Debug mode. This engages the web-based debug mode
DEBUG = False
Expand Down
29 changes: 16 additions & 13 deletions bargate/lib/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,19 +816,6 @@ def connection(srv_path,func_name,active=None,display_name="Home",action='browse
app.logger.error("Exception when uploading a file: " + str(type(ex)) + ": " + str(ex) + traceback.format_exc())
ret.append({'name' : ufile.filename, 'error': 'Failed to stat existing file: ' + str(ex)})
continue

else:
## If the file did exist, check to see if we should overwrite
if fstat:
if not bargate.lib.userdata.get_overwrite_on_upload():
ret.append({'name' : ufile.filename, 'error': 'File already exists. You can enable overwriting files in Account Settings.'})
continue

## Now ensure we're not trying to upload a file on top of a directory (can't do that!)
itemType = bargate.lib.smb.getEntryType(libsmbclient,upload_uri_as_str)
if itemType == bargate.lib.smb.SMB_DIR:
ret.append({'name' : ufile.filename, 'error': "That name already exists and is a directory"})
continue

byterange_start = 0
if 'Content-Range' in request.headers:
Expand All @@ -837,9 +824,25 @@ def connection(srv_path,func_name,active=None,display_name="Home",action='browse

## Actual upload
try:
# Check if we're writing from the start of the file
if byterange_start == 0:
## We're truncating an existing file, or creating a new file
## If the file already exists, check to see if we should overwrite
if fstat:
if not bargate.lib.userdata.get_overwrite_on_upload():
ret.append({'name' : ufile.filename, 'error': 'File already exists. You can enable overwriting files in Settings.'})
continue

## Now ensure we're not trying to upload a file on top of a directory (can't do that!)
itemType = bargate.lib.smb.getEntryType(libsmbclient,upload_uri_as_str)
if itemType == bargate.lib.smb.SMB_DIR:
ret.append({'name' : ufile.filename, 'error': "That name already exists and is a directory"})
continue

## Open the file for the first time, truncating or creating it if necessary
wfile = libsmbclient.open(upload_uri_as_str,os.O_CREAT | os.O_TRUNC | os.O_WRONLY)
else:
## Open the file and seek to where we are going to write the additional data
wfile = libsmbclient.open(upload_uri_as_str,os.O_WRONLY)
wfile.seek(byterange_start)

Expand Down
2 changes: 1 addition & 1 deletion bargate/templates/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<h3><i class="fa fa-fw fa-list-alt"></i> Bargate Changelog<h3>
<hr/>
<h3>1.5.1</h3>
<h3>1.5.2</h3>
<p><em>Released 2016-09-28</em></p>
<ul class="changelog">
<li><i class="fa fa-fw fa-bolt"></i> Added support for 'chunked' file uploads, enabling support for extremely large file uploads</li>
Expand Down

0 comments on commit b872040

Please sign in to comment.