2672b17f44
* feat: sftp test: add tests for ftp and sftp * chore: ci fixes * chore: potential race fix * fix: simplify existence checks * fix: split path differently for ftp * fix: 🤷 * chore: add debug print * chore: lint * chore: idk dude * chore: ? * chore: more logs * chore: wipe mods before tests * chore: logs * chore: wat * chore: wait? * chore: no errors * chore: gh actions are 💩 * fix: always sync after copy * chore: remove some test logs * chore: remove test progress watcher * refactor: change progress to writer * chore: logs * chore: different logs * chore: whoops * chore: moar logs * chore: even moar logs * chore: what is life * chore: why are we here * chore: we are just bags of water floating through space * chore: are you real? * chore: ? * chore: if you get a single update now I call bs * chore: ok what if we just do one? * chore: ok what if we do two? * chore: this should not work * chore: wait no, this one * chore: fml * chore: remove logs * chore: what if we just wait a little * chore: retry * chore: move error * chore: verbose log * chore: remove explicit sleep * chore: remove debug * fix: linux pathing on windows * fix: clean paths properly * fix: fuck ftp * fix: send update on vanilla * feat: parallel ftp * fix: remove potential credential leak
72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package disk
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
var _ Disk = (*localDisk)(nil)
|
|
|
|
type localDisk struct {
|
|
path string
|
|
}
|
|
|
|
type localEntry struct {
|
|
os.DirEntry
|
|
}
|
|
|
|
func newLocal(path string) (Disk, error) {
|
|
return localDisk{path: path}, nil
|
|
}
|
|
|
|
func (l localDisk) Exists(path string) (bool, error) {
|
|
_, err := os.Stat(path)
|
|
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
return false, nil
|
|
}
|
|
|
|
if err != nil {
|
|
return false, fmt.Errorf("failed checking file existence: %w", err)
|
|
}
|
|
|
|
return true, nil
|
|
}
|
|
|
|
func (l localDisk) Read(path string) ([]byte, error) {
|
|
return os.ReadFile(path) //nolint
|
|
}
|
|
|
|
func (l localDisk) Write(path string, data []byte) error {
|
|
return os.WriteFile(path, data, 0777) //nolint
|
|
}
|
|
|
|
func (l localDisk) Remove(path string) error {
|
|
return os.RemoveAll(path) //nolint
|
|
}
|
|
|
|
func (l localDisk) MkDir(path string) error {
|
|
return os.MkdirAll(path, 0777) //nolint
|
|
}
|
|
|
|
func (l localDisk) ReadDir(path string) ([]Entry, error) {
|
|
dir, err := os.ReadDir(path)
|
|
if err != nil {
|
|
return nil, err //nolint
|
|
}
|
|
|
|
entries := make([]Entry, len(dir))
|
|
for i, entry := range dir {
|
|
entries[i] = localEntry{
|
|
DirEntry: entry,
|
|
}
|
|
}
|
|
|
|
return entries, nil
|
|
}
|
|
|
|
func (l localDisk) Open(path string, flag int) (io.WriteCloser, error) {
|
|
return os.OpenFile(path, flag, 0777) //nolint
|
|
}
|