robotframework-archivelibrary icon indicating copy to clipboard operation
robotframework-archivelibrary copied to clipboard

bug in os.path.join

Open QuellaLiu opened this issue 8 years ago • 10 comments

In ‘utils.py’,

Line 22    curdir = os.path.join(basedir, dir)
Line 42    outfile = open(os.path.join(dest, name), 'wb')

When I unzip a file which has a path in it,

unzip

The case fails. “OSError: [Errno 13] Permission denied: '/ram'” That’s because the method ‘os.path.join’ does not work as we expect. For example:

>>> basedir = '/home/ute/ta_kiss_files/example/BTS9_1011_CCNTrace'
>>> dir = '/ram'
>>> curdir = os.path.join(basedir, dir)
>>> print curdir
/ram

After I change the utils.py as below,

Line 22    curdir = os.path.join(basedir, dir)
Change to  curdir = basedir + '/' + dir
Line 42    outfile = open(os.path.join(dest, name), 'wb')
Change to  outfile = open(dest + '/' + name, 'wb')

Case passes, because,

>>> curdir = basedir + '/' + dir
>>> print curdir
/home/ute/ta_kiss_files/example/BTS9_1011_CCNTrace///ram
>>>

That is what we expect.

QuellaLiu avatar Jul 10 '17 06:07 QuellaLiu

@QuellaLiu Thanks, could you please submit PR with your suggested changes?

vkosuri avatar Jul 10 '17 06:07 vkosuri

os.path.join() does work as expected, it is supposed to break the concatenation at the first absolute path. From the docs:

If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component.

Doing it manually - with basedir + '/' + dir is very dangerous, may easily produce invalid paths (that's why that module and function exist on the first place :)

I suspect it's a combination of the construct in the particulars zip, plus this code in utils.py:56

elif '/' in name:
    path = name[0:name.rindex('/')]
    dirs.add(path)

Can you please attach the zip file you're seeing the bug for, plus the exact arguments you're calling the keywords/methods with? Thank you.

tminakov avatar Jul 10 '17 07:07 tminakov

I submitted a PR several days ago, but can't add any reviewer. I don't know what's the next step. Who will merge the change?

LiuQiE avatar Jul 17 '17 01:07 LiuQiE

my PR: https://github.com/LiuQiE/robotframework-archivelibrary/pull/1

LiuQiE avatar Jul 17 '17 01:07 LiuQiE

@LiuQiE you need to submit your PR to this repo.

bulkan avatar Jul 17 '17 01:07 bulkan

Sorry! I submitted a PR to this repo just now.

LiuQiE avatar Jul 17 '17 03:07 LiuQiE

I can see the PR is merged. When will you put the latest version in https://pypi.python.org/pypi/robotframework-archivelibrary ? Thank you very much!

LiuQiE avatar Jul 19 '17 05:07 LiuQiE

Hi, Bulkan, could you please update https://pypi.python.org/pypi/robotframework-archivelibrary as soon as possible? Thank you!

LiuQiE avatar Jul 25 '17 02:07 LiuQiE

@tminakov can you please comment on this PR https://github.com/bulkan/robotframework-archivelibrary/pull/30 the change looks good and not manually creating paths, just want a third opinion on it.

bulkan avatar Jul 25 '17 02:07 bulkan

any progress on https://pypi.python.org/pypi/robotframework-archivelibrary?

LiuQiE avatar Aug 02 '17 07:08 LiuQiE