-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle a compound extension in new_untitled #2949
Conversation
basename, ext = os.path.splitext(filename) | ||
# Extract the full suffix from the filename (e.g. .tar.gz) | ||
dirname = os.path.dirname(filename) | ||
basename = os.path.basename(filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be summarised as dirname, basename = os.path.split(filename)
.
Also, I think we should leave in the .strip('/')
that was there before, so that passing in foo/bar/
gives you foo/bar1
, not foo/bar/1
.
basename = os.path.join(dirname, parts[0]) | ||
suffix = '.' + '.'.join(parts[1:]) | ||
if suffix == '.': | ||
suffix = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using str.partition():
name, dot, ext = basename.partition('.')
basename = os.path.join(dirname, name)
suffix = dot+ext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Updated.
if not self.exists(u'{}/{}'.format(path, name)): | ||
name = u'{basename}{insert}{suffix}'.format(basename=basename, | ||
insert=insert_i, suffix=suffix) | ||
if not self.exists(os.path.join(path, name)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, hang on. This function works with an API path, which is always /
separated, rather than a platform-dependent native path. So using os.path.split
and os.path.join
is wrong here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Looking again, filename
should never have a directory in it.
Thanks, merging. |
Ha, that was easy, thanks for your patience ;). |
@meeseeksdev backport to 5.2.1 |
This allows file names with compound extensions (e.g.
.tar.gz
) to be properly incremented when creating a new file. Previously we would end up withuntitled.tar1.gz
.cf jupyterlab/jupyterlab#3113