mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Simplified FileSize function
This commit is contained in:
parent
3bb1c015c8
commit
b10d8a075b
2 changed files with 3 additions and 9 deletions
8
utils.go
8
utils.go
|
@ -163,13 +163,7 @@ func HashFile(filename string) (hash string, err error) {
|
||||||
|
|
||||||
// FileSize returns the size of a file
|
// FileSize returns the size of a file
|
||||||
func FileSize(filename string) (int, error) {
|
func FileSize(filename string) (int, error) {
|
||||||
f, err := os.Open(filename)
|
fi, err := os.Stat(filename)
|
||||||
if err != nil {
|
|
||||||
return -1, err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
fi, err := f.Stat()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,8 @@ func TestFileSize(t *testing.T) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("should return an error")
|
t.Error("should return an error")
|
||||||
}
|
}
|
||||||
if s > 0 {
|
if s != -1 {
|
||||||
t.Errorf("size should be 0, got: %d", s)
|
t.Errorf("size should be -1, got: %d", s)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue