Skip to content

More aggressively validate ambiguous file paths#62

Open
jtratner wants to merge 1 commit intocounsyl:masterfrom
jtratner:do-not-allow-writing-with-trailing-slash
Open

More aggressively validate ambiguous file paths#62
jtratner wants to merge 1 commit intocounsyl:masterfrom
jtratner:do-not-allow-writing-with-trailing-slash

Conversation

@jtratner
Copy link
Copy Markdown
Contributor

@jtratner jtratner commented Jan 20, 2018

Closes #52

Generally, validate ambiguous paths more robustly and almost always error when they end in trailing slash.

API Additions

  • Add stor.test.TestCase that allows mocking out of both swift AND s3
    functionality in a test case.

Bug Fixes

  • open() will raise with an OBS path that ends in trailing slash, rather
    than generating an invalid/difficult OBS object.

Deprecations

  • Add warning about calling open() or copy() with OBS or filesystem
    paths that are ambiguous or end in a trailing slash. In the next version of
    stor, this will be an error, to prevent differences between local and OBS
    code. Set stor:raise_on_ambiguous_filesystem_path to get this behavior
    now.
  • is_ambiguous() is now deprecated.

cc @kristjaneerik

@jtratner jtratner force-pushed the do-not-allow-writing-with-trailing-slash branch 4 times, most recently from f6dfb91 to 32921e7 Compare January 20, 2018 06:52
Closes counsyl#52

* Error on filepaths with trailing slash because they do not have a name
  and thus appear to be directories.
* Add validation for bad paths to ``OBSFile``.
* Warn if filesystem paths would not pass this validation (otherwise you
  have the possibility of something that works locally and not on OBS).
  This can be set to raise instead if you set
  ``stor.raise_on_ambiguous_filesystem_path`` to be True
* Deprecate ``is_ambiguous()`` which didn't 100% serve the purpose we
  wanted anyways (since you can always tell when user means directory
  because of the user of ``copytree()`` and/or ``-r``)

Sem-Ver: feature
@jtratner jtratner force-pushed the do-not-allow-writing-with-trailing-slash branch from 32921e7 to 4a498bf Compare January 24, 2018 09:20
Comment thread stor/base.py
"""
kwargs.pop('swift_upload_kwargs', None)
if kwargs.pop('swift_upload_kwargs', None):
warnings.warn('swift_upload_kwargs will be removed in stor 2.0')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem discussed elsewhere in PR?

Comment thread stor/obs.py
if six.PY2 and encoding: # pragma: no cover
raise TypeError('encoding not supported in Python 2')
# TODO (jtratner): in stor 2.0 remove this explicit check and the warning
if pth.endswith('/'):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want the and not self.ext part from is_ambiguous ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't call to utils.validate_file_path right below sufficient?

Comment thread stor/swift.py
passed as keyword args to `SwiftPath.upload` if any writes
occur on the opened resource.

swift_upload_options (dict): DEPRECATED (use `stor.settings.use()` instead).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stor.settings.use() already added correct?

Comment thread stor/utils.py
# we use a try/except so that it's easier for the reader to tell why the exception was
# generated.
try:
if not dest.name:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it slightly less explicit to rely on dest.name to verify no trailing slash rather than doing directly?

Comment thread stor/utils.py
return answer


def validate_file_path(dest, _warn=False):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: dest name implies this is always a check on destination path but it's called on both destination and source paths.

Comment thread stor/utils.py
if not dest.ext:
raise ValueError('file paths without extension are ambiguous')
except ValueError as e:
if ((_warn or is_filesystem_path(dest)) and
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should is_filesystem_path be moved earlier on since ambiguous paths are fine in that setting so no need to do any validations?

Comment thread stor/utils.py
if not dest.name:
raise ValueError('file paths may not end with trailing slash')
if not dest.ext:
raise ValueError('file paths without extension are ambiguous')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requiring extensions for everything seems more restrictive that necessary and beyond what's required to resolve issue no?

Copy link
Copy Markdown
Collaborator

@krhaas krhaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a pass, back to you

Copy link
Copy Markdown
Collaborator

@krhaas krhaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

back to you @jtratner

Copy link
Copy Markdown
Contributor

@pkaleta pkaleta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding empty review to remove this from my gh PRs list ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants