Skip to content
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

WIP: Verify paths to be writable #400

Closed

Conversation

nicorikken
Copy link
Member

To resolve the regression from #347 this code checks if files can
be written and throws an error otherwise.

Signed-off-by: Nico Rikken nico@nicorikken.eu

To resolve the regression from fsfe#347 this code checks if files can
be written and throws an error otherwise.

Signed-off-by: Nico Rikken <nico@nicorikken.eu>
@nicorikken
Copy link
Member Author

nicorikken commented Aug 6, 2021

Please consider this a work in progress or suggestion. This version works like:

reuse addheader -c "mycorp" -l Apache-2.0 -y 2021 tmp/test.sh
gebruik: reuse addheader [-h] [--copyright COPYRIGHT] [--license LICENSE] [--year YEAR] [--style {applescript,aspx,bat,bibtex,c,css,f,handlebars,haskell,html,jinja,jsx,lisp,m4,ml,plantuml,python,rst,tex}]
                         [--copyright-style {spdx,spdx-symbol,string,string-c,string-symbol,symbol}] [--template TEMPLATE] [--exclude-year] [--single-line] [--multi-line] [--explicit-license]
                         [--skip-unrecognised]
                         path [path ...]
reuse addheader: error: 'tmp/test.sh' is not writable, please use --explicit-license

It might be more user-friendly to switch to an explicit license file directly, but that would require more rework in the general header.py structure. Both cases are now handled separately, and this exceptional case should have to jump between these code paths.

Note: this does not yet include a unit test or translation.

This unit test checks if an error is raised when a file cannot be
written to. This test is currently not very discriminating as it
would also succeed for other errors.

Signed-off-by: Nico Rikken <nico@nicorikken.eu>
@nicorikken
Copy link
Member Author

I added a unit test, but that one needs more work, as it is too generic. It would also succeed if this code change wouldn't be made as the regression would also result in an error.

@mxmehl mxmehl changed the title Verify paths to be writable WIP: Verify paths to be writable Aug 7, 2021
CharString pushed a commit to CharString/reuse-tool that referenced this pull request Oct 1, 2021
Incorporates good ideas from pr fsfe#400. I didn't see it existed when I
created this pr.

 - _check -> _verify to match naming style of other verification
    functions.
 - split the parameters into paths and parser
Copy link

@CharString CharString left a comment

Choose a reason for hiding this comment

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

I've adopted the neater function name and signature of this pr in #418 and fixed the case of passing --style.

@@ -553,6 +564,7 @@ def run(args, project: Project, out=sys.stdout) -> int:

# Verify line handling and comment styles before proceeding
if args.style is None and not args.explicit_license:
_verify_writable(paths, args.parser)

Choose a reason for hiding this comment

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

I overlooked this pr when I created pr #418, which does almost exactly the same, except for when the check is done.
Isn't the check needed even when args.style is set to a certain comment-style?

Choose a reason for hiding this comment

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

It is. I've added a --style in the #418 test.

if not os.access(path, os.W_OK):
parser.error(
_(
"'{path}' is not writable, please use --explicit-license"

Choose a reason for hiding this comment

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

In #418, I opted for not breaking on first error, but collecting all non-writable paths and mentioning them all at once, so the user can react to the complete set of problems.
Also, #418 doesn't mention --explicit-license but reuses the existing "can't write to'{}'" string that is already translated to different languages. And I can imagine cases where chmod is a better solution than --explicit-license

mxmehl pushed a commit to CharString/reuse-tool that referenced this pull request Nov 10, 2021
Incorporates good ideas from pr fsfe#400. I didn't see it existed when I
created this pr.

 - _check -> _verify to match naming style of other verification
    functions.
 - split the parameters into paths and parser
@nicorikken
Copy link
Member Author

This pull request has become obsolete.

@nicorikken nicorikken closed this Jan 19, 2022
@nicorikken nicorikken deleted the feature/check-write-permission branch February 3, 2022 19:00
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.

2 participants