Handle a compound extension in new_untitled#2949
Merged
Merged
Conversation
takluyver
reviewed
Oct 20, 2017
| 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) |
Member
There was a problem hiding this comment.
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.
takluyver
reviewed
Oct 20, 2017
| basename = os.path.join(dirname, parts[0]) | ||
| suffix = '.' + '.'.join(parts[1:]) | ||
| if suffix == '.': | ||
| suffix = '' |
Member
There was a problem hiding this comment.
How about using str.partition():
name, dot, ext = basename.partition('.')
basename = os.path.join(dirname, name)
suffix = dot+ext
takluyver
reviewed
Oct 20, 2017
| 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)): |
Member
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
Updated. Looking again, filename should never have a directory in it.
Member
|
Thanks, merging. |
Contributor
Author
|
Ha, that was easy, thanks for your patience ;). |
Contributor
|
@meeseeksdev backport to 5.2.1 |
gnestor
pushed a commit
that referenced
this pull request
Oct 27, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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