Skip to content

py3k: file.truncate() changes the file position #45664

Closed

Description

@amauryfa
BPO 1323
Nosy @gvanrossum, @amauryfa
Files
  • truncate.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2007-10-25.23:23:49.712>
    created_at = <Date 2007-10-24.22:30:33.076>
    labels = ['OS-windows']
    title = 'py3k: file.truncate() changes the file position'
    updated_at = <Date 2007-10-25.23:23:49.689>
    user = 'https://github.com/amauryfa'

    bugs.python.org fields:

    activity = <Date 2007-10-25.23:23:49.689>
    actor = 'gvanrossum'
    assignee = 'none'
    closed = True
    closed_date = <Date 2007-10-25.23:23:49.712>
    closer = 'gvanrossum'
    components = ['Windows']
    creation = <Date 2007-10-24.22:30:33.076>
    creator = 'amaury.forgeotdarc'
    dependencies = []
    files = ['8606']
    hgrepos = []
    issue_num = 1323
    keywords = ['patch']
    message_count = 2.0
    messages = ['56732', '56763']
    nosy_count = 2.0
    nosy_names = ['gvanrossum', 'amaury.forgeotdarc']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1323'
    versions = ['Python 3.0']

    Activity

    1. amauryfa commented on Oct 24, 2007

      @amauryfa
      ContributorAuthor

      This patch corrects a problem in test_file.py on Windows:
      f.truncate() seeks to the truncation point, but does not empty the
      buffers. In the test, f.tell() returns -1...

      Now we flush the file before, and seek to the initial position after.
      The same trick was present in 2.5, in fileobject.c::file_truncate. The
      same comments apply as well.

      Reviewers needed! Flushing may change the behaviour, but seems more
      correct to me (and closer to python2.5). Should we add specific tests
      for this?

      Also, change the test to be sure to close the file before trying to
      remove it (it seems that in a finally: block, the exception still
      references all the local variables in the traceback). Otherwise the
      previous problem is hidden by a "file locked" error in the finally block.

    2. gvanrossum commented on Oct 25, 2007

      @gvanrossum
      Member

      Looks fine to me.
      Committed revision 58658.

    3. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions