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
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package disk
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log/slog"
|
|
"net/url"
|
|
"path/filepath"
|
|
)
|
|
|
|
type Disk interface {
|
|
// Exists checks if the provided file or directory exists
|
|
Exists(path string) (bool, error)
|
|
|
|
// Read returns the entire file as a byte buffer
|
|
//
|
|
// Returns error if provided path is not a file
|
|
Read(path string) ([]byte, error)
|
|
|
|
// Write writes provided byte buffer to the path
|
|
Write(path string, data []byte) error
|
|
|
|
// Remove deletes the provided file or directory recursively
|
|
Remove(path string) error
|
|
|
|
// MkDir creates the provided directory recursively
|
|
MkDir(path string) error
|
|
|
|
// ReadDir returns all entries within the directory
|
|
//
|
|
// Returns error if provided path is not a directory
|
|
ReadDir(path string) ([]Entry, error)
|
|
|
|
// Open opens provided path for writing
|
|
Open(path string, flag int) (io.WriteCloser, error)
|
|
}
|
|
|
|
type Entry interface {
|
|
IsDir() bool
|
|
Name() string
|
|
}
|
|
|
|
func FromPath(path string) (Disk, error) {
|
|
parsed, err := url.Parse(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to parse path: %w", err)
|
|
}
|
|
|
|
switch parsed.Scheme {
|
|
case "ftp":
|
|
slog.Info("connecting to ftp")
|
|
return newFTP(path)
|
|
case "sftp":
|
|
slog.Info("connecting to sftp")
|
|
return newSFTP(path)
|
|
}
|
|
|
|
slog.Info("using local disk", slog.String("path", path))
|
|
return newLocal(path)
|
|
}
|
|
|
|
// clean returns a unix-style path
|
|
func clean(path string) string {
|
|
return filepath.ToSlash(filepath.Clean(path))
|
|
}
|