Giter Site home page Giter Site logo

Comments (2)

diazona avatar diazona commented on July 17, 2024 3

This piqued my curiosity on Mastodon, and after investigating for a little while I have a suggestion: does it seem reasonable that render_report() should not delete a file that it didn't originally create? If so, it could try to open the file in exclusive mode, falling back to write mode, and set delete_file to True or False depending on which one worked.

Alternatively, it could try to delete the file first, before creating it, which should be safe in the sense that it's going to overwrite the file anyway. If the initial deletion fails, that's probably a good sign that it shouldn't try to delete the file afterwards either. The only way I can think of that this goes awry is if it's told to use an output file that exists and is writable but cannot be deleted, and then the report generation fails, leaving the file with potentially garbage content. But if that's a concern, it could just check whether the file is seekable() and if so, truncate it in place if deletion fails; if not, there's probably no way to undo writing that garbage content anyway.

If any of this sounds good, I'd be happy to contribute a PR (I've gotten more than enough good use out of coverage.py that it seems only fair to offer a contribution), or someone else is welcome to take these ideas and make their own PR.

from coveragepy.

nedbat avatar nedbat commented on July 17, 2024

A simple way to reproduce:

% cat > hello.py
print("hello")
% coverage run hello.py
hello
% rm hello.py
% coverage json -q -o /dev/stdout
... (the error shown above) ...
PermissionError: [Errno 1] Operation not permitted: '/dev/stdout'

from coveragepy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.