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

Fix regression for files without permissions. #418

Merged
merged 4 commits into from
Nov 10, 2021

Conversation

CharString
Copy link

Closes #398

CharString pushed a commit to CharString/reuse-tool that referenced this pull request Oct 1, 2021
When working on fsfe#418, one of my commits tripped on isort in CI. This
should prevent this in the future.
@nicorikken
Copy link
Member

Sorry for not looking into this sooner. Thanks for working on this.
I still get the stacktrace output. Am I doing something wrong?

$ ls -la tmp/test2.sh 
-rw-r--r-- 1 root root 49 nov  9 10:55 tmp/test2.sh

$ git log -n 1
commit 0e0e4668d14a98f155dc9b1c69e6234c2abb31a3 (HEAD -> issue_398, charstring/issue_398)
Author: Chris Wesseling <Chris.Wesseling@cwi.nl>
Date:   Fri Oct 1 17:04:15 2021 +0200

    Fix linting error and typo.

$ ./venv/bin/reuse --version
reuse 0.13.1.dev33+g0e0e466

$ ./venv/bin/reuse addheader -c 'mycorp' -l Apache-2.0 -y 2020 tmp/test2.sh
Traceback (most recent call last):
  File "./venv/bin/reuse", line 33, in <module>
    sys.exit(load_entry_point('reuse==0.13.1.dev33+g0e0e466', 'console_scripts', 'reuse')())
  File "/home/nico/Software/fsfe/reuse-tool/venv/lib/python3.8/site-packages/reuse/_main.py", line 256, in main
    return parsed_args.func(parsed_args, project, out)
  File "/home/nico/Software/fsfe/reuse-tool/venv/lib/python3.8/site-packages/reuse/header.py", line 605, in run
    result += _add_header_to_file(
  File "/home/nico/Software/fsfe/reuse-tool/venv/lib/python3.8/site-packages/reuse/header.py", line 436, in _add_header_to_file
    with path.open("w", encoding="utf-8", newline=line_ending) as fp:
  File "/usr/lib/python3.8/pathlib.py", line 1222, in open
    return io.open(self, mode, buffering, encoding, errors, newline,
  File "/usr/lib/python3.8/pathlib.py", line 1078, in _opener
    return self._accessor.open(self, flags, mode)
PermissionError: [Errno 13] Permission denied: 'tmp/test2.sh'

@mxmehl
Copy link
Member

mxmehl commented Nov 9, 2021

I cannot reproduce your error, @nicorikken. For me, the following happens which is what I think @CharString intended:

$ reuse --version
reuse 0.13.1.dev33+g0e0e466
$ echo foo > bar.md && chmod 444 bar.md
$ ls -l bar.md 
.r--r--r-- 4 max max  9 Nov 16:20 bar.md
$ reuse addheader -c 'mycorp' -l Apache-2.0 -y 2020 bar.md 
usage: 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: can't write to 'bar.md'
$ reuse addheader -c 'mycorp' -l Apache-2.0 -y 2020 --explicit-license bar.md
Successfully changed header of bar.md.license
$ cat bar.md.license
SPDX-FileCopyrightText: 2020 mycorp

SPDX-License-Identifier: Apache-2.0

Or am I missing something?

@nicorikken
Copy link
Member

Hmm, I have to do some more debugging in my system them to pinpoint it.

@nicorikken
Copy link
Member

Perhaps there was some state left from my own Python code. I did a clean clone in a separate directory and now it works:

.venv/bin/reuse addheader -c 'mycorp' -l Apache-2.0 -y 2020 tmp/script.sh 
usage: 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: can't write to 'tmp/script.sh'

Great!!

The code also looks good to me, so Max I approve.

@CharString
Copy link
Author

@nicorikken No problem

@mxmehl
Copy link
Member

mxmehl commented Nov 10, 2021

Yay, happy that it worked out :)

Chris Wesseling and others added 4 commits November 10, 2021 11:42
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
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.

Regression for files without permissions
3 participants