mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-23 05:07:51 +01:00
Warehouse.FileExists return fileSize instead of fileInfo
This commit is contained in:
@@ -19,10 +19,10 @@ import (
|
||||
const merkleCompanionExt = ".merkle"
|
||||
|
||||
// MerkleFileExists checks if the merkle companion file exists. It returns StatusInvalidHash, StatusFileNotFound, or StatusOK.
|
||||
func (wh *Warehouse) MerkleFileExists(hash []byte) (path string, fileInfo os.FileInfo, status int, err error) {
|
||||
func (wh *Warehouse) MerkleFileExists(hash []byte) (path string, fileSize uint64, status int, err error) {
|
||||
hashA, err := ValidateHash(hash)
|
||||
if err != nil {
|
||||
return "", nil, StatusInvalidHash, err
|
||||
return "", 0, StatusInvalidHash, err
|
||||
}
|
||||
|
||||
a, b := buildPath(wh.Directory, hashA)
|
||||
@@ -30,10 +30,10 @@ func (wh *Warehouse) MerkleFileExists(hash []byte) (path string, fileInfo os.Fil
|
||||
|
||||
if fileInfo, err := os.Stat(path); err == nil {
|
||||
// file exists
|
||||
return path, fileInfo, StatusOK, nil
|
||||
return path, uint64(fileInfo.Size()), StatusOK, nil
|
||||
}
|
||||
|
||||
return "", nil, StatusFileNotFound, os.ErrNotExist
|
||||
return "", 0, StatusFileNotFound, os.ErrNotExist
|
||||
}
|
||||
|
||||
// createMerkleCompanionFile creates a merkle companion file. If the merkle companion file already exists, it is overwritten.
|
||||
|
||||
@@ -210,10 +210,10 @@ func (wh *Warehouse) DeleteFile(hash []byte) (status int, err error) {
|
||||
}
|
||||
|
||||
// FileExists checks if the file exists. It returns StatusInvalidHash, StatusFileNotFound, or StatusOK.
|
||||
func (wh *Warehouse) FileExists(hash []byte) (path string, fileInfo os.FileInfo, status int, err error) {
|
||||
func (wh *Warehouse) FileExists(hash []byte) (path string, fileSize uint64, status int, err error) {
|
||||
hashA, err := ValidateHash(hash)
|
||||
if err != nil {
|
||||
return "", nil, StatusInvalidHash, err
|
||||
return "", 0, StatusInvalidHash, err
|
||||
}
|
||||
|
||||
a, b := buildPath(wh.Directory, hashA)
|
||||
@@ -221,10 +221,10 @@ func (wh *Warehouse) FileExists(hash []byte) (path string, fileInfo os.FileInfo,
|
||||
|
||||
if fileInfo, err := os.Stat(path); err == nil {
|
||||
// file exists
|
||||
return path, fileInfo, StatusOK, nil
|
||||
return path, uint64(fileInfo.Size()), StatusOK, nil
|
||||
}
|
||||
|
||||
return "", nil, StatusFileNotFound, os.ErrNotExist
|
||||
return "", 0, StatusFileNotFound, os.ErrNotExist
|
||||
}
|
||||
|
||||
// DeleteWarehouse deletes all files in the warehouse
|
||||
|
||||
Reference in New Issue
Block a user