🔷 (File Transferring Utility) Transfer files through the Net 🔷
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
708 B

package receiver
import (
"fmt"
"os"
"github.com/Unbewohnte/FTU/checksum"
)
// Receiver`s file struct. Used internally by receiver
type File struct {
Filename string
Filesize uint64
CheckSum checksum.CheckSum
}
// Goes through all files in the downloads directory and compares their
// names with the name of the file that is about to be downloaded
func (r *Receiver) CheckIfFileAlreadyExists() (bool, error) {
contents, err := os.ReadDir(r.DownloadsFolder)
if err != nil {
return false, fmt.Errorf("could not get contents of the downloads` directory: %s", err)
}
for _, file := range contents {
if file.Name() == r.FileToDownload.Filename {
return true, nil
}
}
return false, nil
}