gallantlab / cottoncandy

sugar for s3
http://gallantlab.github.io/cottoncandy/
BSD 2-Clause "Simplified" License
33 stars 16 forks source link

problem when uploading file with no object name #51

Closed alexhuth closed 6 years ago

alexhuth commented 6 years ago

Uploading a file without specifying the object_name throws an error. Not sure if this is python3 specific, and I could probably fix it but I'm on a time crunch, so I thought I'd at least post it.

In [13]: cci.upload_from_file('stuff.tar.gz')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-b4e7b63eb52e> in <module>()
----> 1 cci.upload_from_file('stuff.tar.gz')

/home/huth/cottoncandy/cottoncandy/interfaces.py in upload_from_file(self, flname, object_name, ExtraArgs)
    329         response : boto3 response
    330         """
--> 331         return self.backend_interface.upload_file(flname, object_name, ExtraArgs['ACL'])
    332 
    333     def upload_from_directory(self, disk_path, cloud_path=None,

/home/huth/cottoncandy/cottoncandy/s3client.py in upload_file(self, file_name, cloud_name, permissions)
    359         if file_name is None:
    360             file_name = os.path.abspath(file_name)
--> 361         s3_object = self.get_s3_object(cloud_name)
    362         return s3_object.upload_file(file_name, ExtraArgs = dict(ACL = permissions))
    363 

/home/huth/cottoncandy/cottoncandy/utils.py in iremove_root(self, object_name, *args, **kwargs)
    257     @wraps(input_function)
    258     def iremove_root(self, object_name, *args, **kwargs):
--> 259         object_name = re.sub('//+', '/', object_name)
    260 
    261         if object_name == '':

/home/huth/anaconda3/lib/python3.5/re.py in sub(pattern, repl, string, count, flags)
    180     a callable, it's passed the match object and must return
    181     a replacement string to be used."""
--> 182     return _compile(pattern, flags).sub(repl, string, count)
    183 
    184 def subn(pattern, repl, string, count=0, flags=0):

TypeError: expected string or bytes-like object

I think the problem is that object_name is None, making the re.sub function barf.

anwarnunez commented 6 years ago

oops... i think that's a bug. just pushed a fix (69abf89aa8c3f51f27fa36a3943b614d7a33e703) try it now

alexhuth commented 6 years ago

works! thanks