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

os: Stat().Size contains incorrect value #23493

Closed
linux-support opened this issue Jan 20, 2018 · 4 comments
Closed

os: Stat().Size contains incorrect value #23493

linux-support opened this issue Jan 20, 2018 · 4 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@linux-support
Copy link

I did compare the contents of FileInfo.Size returned by several stat functions. The resutle of the tests varies depending on the utilized methodes.

testcase 1

fi, err = os.Stat(fqfn)
fi.Size contains a value, that does not match the file size.

testcase 2

fi, err = os.Lstat(fqfn)
fi.Size contains a value, that does not match the file size.

testcase 3

file, err := os.Open( fqfn )
fi, err = file.Stat(fqfn)
fi.Size contains a value, that is correct!

What version of Go are you using (go version)?

1.9.2

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

windows, amd64
Linux, amd64

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

The value of the Size property should be the same regardless the utilized method. In all tree cases a FileInfo object is returned, that should describe the referenced file correctly.

In my test scenario I did create a text file containing one single byte. All three test cases should return '1' as size.

What did you see instead?

When calling the stat methods I get the following results for a 1 byte file:
2018-01-20 17:09:56, FILE "Neues Textdokument.txt"
Size: 4953040, Neues Textdokument.txt <<-- os.Stat & os.Lstat
Size: 1 <<-- file.Stat
2018-01-20 17:09:57, FILE "Neues Textdokument.txt"
Size: 4953040, Neues Textdokument.txt <<-- os.Stat & os.Lstat
Size: 1 <<-- file.Stat

@0xmohit
Copy link
Contributor

0xmohit commented Jan 20, 2018

Are you making the function call, i.e. saying fi.Size() and not fi.Size?

Running go vet on the source might also give a clue.

@mvdan
Copy link
Member

mvdan commented Jan 20, 2018

A full program to reproduce this would also be useful. Otherwise, plenty of things could be going on here.

@mvdan mvdan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 20, 2018
@linux-support
Copy link
Author

I will provide a sample program with some comments how I did build binaries.

@linux-support
Copy link
Author

linux-support commented Jan 20, 2018

Instead of requesting the file size by utilizing fi.Size() my program did contain fi.Size. So it's my fault.
I will close the issue.

@mikioh mikioh changed the title os.Stat().Size contains incorrect value os: Stat().Size contains incorrect value Jan 26, 2018
@golang golang locked and limited conversation to collaborators Jan 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants