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

bpo-40105: Truncating file if opened in append mode. #19337

Merged
merged 7 commits into from
Sep 28, 2020

Conversation

mzr
Copy link
Contributor

@mzr mzr commented Apr 3, 2020

Implemented a test for this behaviour.

If we just truncate the test fails for Unseekable file types. In current implementation, those type of files can't be opened in the append ('a') mode anyway, so we could make a check for that in the future.

https://bugs.python.org/issue40105

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@mzr

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@mzr mzr changed the title Truncating file if opened in append mode. bpo-40105: Truncating file if opened in append mode. Apr 3, 2020
Copy link
Contributor

@taleinat taleinat left a comment

Choose a reason for hiding this comment

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

This looks good! Just a couple of minor comments regarding the test.

with zipfile.ZipFile(TESTFN,mode="a") as zipf:
zipf.comment = b"shorter comment"
zipf.comment = one_byte_shorter_comment
self.assertEqual(original_zip_size, os.path.getsize(TESTFN) + 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Testing for the precise size is too restrictive IMO. It would be better to just test that the size was reduced. That would also allow keeping the existing comments.

Comment on lines 1856 to 1857
original_comment = b"original comment that's longer"
one_byte_shorter_comment = original_comment[:-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO extracting these to variables makes the test code harder to understand rather than easier. I suggest undoing this change.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@mzr
Copy link
Contributor Author

mzr commented Sep 28, 2020

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

Copy link
Contributor

@taleinat taleinat left a comment

Choose a reason for hiding this comment

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

Looks good!

@taleinat taleinat added the type-bug An unexpected behavior, bug, or error label Sep 28, 2020
@taleinat taleinat merged commit ff9147d into python:master Sep 28, 2020
@miss-islington
Copy link
Contributor

Thanks @mzr for the PR, and @taleinat for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 28, 2020
…onGH-19337)

(cherry picked from commit ff9147d)

Co-authored-by: Jan Mazur <16736821+mzr@users.noreply.github.com>
@bedevere-bot
Copy link

GH-22436 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Sep 28, 2020
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 28, 2020
…onGH-19337)

(cherry picked from commit ff9147d)

Co-authored-by: Jan Mazur <16736821+mzr@users.noreply.github.com>
@bedevere-bot
Copy link

GH-22437 is a backport of this pull request to the 3.8 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.8 only security fixes label Sep 28, 2020
@mzr mzr deleted the zipfile-shorten-comment-fix branch September 28, 2020 19:04
miss-islington added a commit that referenced this pull request Sep 28, 2020
…9337)

(cherry picked from commit ff9147d)

Co-authored-by: Jan Mazur <16736821+mzr@users.noreply.github.com>
@taleinat taleinat added the needs backport to 3.9 only security fixes label Sep 28, 2020
@miss-islington
Copy link
Contributor

Thanks @mzr for the PR, and @taleinat for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 28, 2020
…onGH-19337)

(cherry picked from commit ff9147d)

Co-authored-by: Jan Mazur <16736821+mzr@users.noreply.github.com>
@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Sep 28, 2020
@bedevere-bot
Copy link

GH-22439 is a backport of this pull request to the 3.9 branch.

miss-islington added a commit that referenced this pull request Sep 28, 2020
…9337)

(cherry picked from commit ff9147d)

Co-authored-by: Jan Mazur <16736821+mzr@users.noreply.github.com>
shihai1991 added a commit to shihai1991/cpython that referenced this pull request Sep 29, 2020
* origin/master: (113 commits)
  bpo-41773: Raise exception for non-finite weights in random.choices().  (pythonGH-22441)
  bpo-41873: Add vectorcall for float() (pythonGH-22432)
  bpo-41861: Convert _sqlite3 PrepareProtocolType to heap type (pythonGH-22428)
  bpo-41842: Add codecs.unregister() function (pythonGH-22360)
  bpo-41875: Use __builtin_unreachable when possible (pythonGH-22433)
  bpo-40105: ZipFile truncate in append mode with shorter comment (pythonGH-19337)
  bpo-41870: Use PEP 590 vectorcall to speed up bool()  (pythonGH-22427)
  [doc] Leverage the fact that the actual types can now be indexed for typing (pythonGH-22340)
  bpo-41861: Convert _sqlite3 cache and node static types to heap types (pythonGH-22417)
  bpo-41858: Clarify line in optparse doc (pythonGH-22407)
  Revert "Fix all Python Cookbook links (python#22205)" (pythonGH-22424)
  bpo-1635741: Port _bisect module to multi-phase init (pythonGH-22415)
  bpo-41428: Fix compiler warning in unionobject.c (pythonGH-22416)
  Fix logging error message (pythonGH-22410)
  bpo-39934: Account for control blocks in 'except' in compiler. (pythonGH-22395)
  bpo-41775: Make 'IDLE Shell' the shell title  (python#22399)
  bpo-41428: Fix compiler warnings in unionobject.c (pythonGH-22388)
  bpo-41654: Fix compiler warning in MemoryError_dealloc() (pythonGH-22387)
  bpo-41833: threading.Thread now uses the target name (pythonGH-22357)
  bpo-30155: Add macros to get tzinfo from datetime instances (pythonGH-21633)
  ...
xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants