Skip to content

gfile.Copy does not overwrite dest file properly on posix filesystems #28508

@tsawada

Description

@tsawada

Describe the current behavior
gfile.Copy(overwrite=True) does not truncate the destination file before overwriting. That means if the src file is shorter than the dest file, the resulting dest file contains the mix of the two.

Describe the expected behavior
gfile.Copy(overwrite=True) results in having the exact same content of src file in the dest file.

Code to reproduce the issue

$ echo 'aaa' > a.txt
$ echo 'bbbbbb' > b.txt
$ python3 -c "from tensorflow import gfile; gfile.Copy('a.txt', 'b.txt', overwrite=True)"
$ cat b.txt
aaa
bb

Tested with pip3 install tensorflow==1.13.1, python 3.5.2
b.txt should have aaa as the content, not aaa\nbb.

Ref. https://www.tensorflow.org/api_docs/python/tf/gfile/Copy

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions