fixed correct proton drive upload with vertical slices
This commit is contained in:
+51
-7
@@ -10,12 +10,10 @@ import (
|
||||
|
||||
const binaryName = "proton-drive"
|
||||
|
||||
// Lookup returns the full path to the proton-drive binary in PATH.
|
||||
func Lookup() (string, error) {
|
||||
return exec.LookPath(binaryName)
|
||||
}
|
||||
|
||||
// CheckAuth verifies that the user is authenticated by listing /my-files.
|
||||
func CheckAuth() error {
|
||||
binary, err := Lookup()
|
||||
if err != nil {
|
||||
@@ -32,11 +30,57 @@ func CheckAuth() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Upload uploads localPath to remotePath on Proton Drive.
|
||||
// remotePath is a full path including filename (e.g. /my-files/md/report.md).
|
||||
// The CLI uploads to a parent directory and preserves the local filename,
|
||||
// so if the remote filename differs from the local one, a temp copy is staged.
|
||||
// Existing remote files are overwritten (--conflict-strategy replace).
|
||||
// EnsureRemoteParent creates the parent remote directory if it doesn't exist.
|
||||
func EnsureRemoteParent(remoteDir string) error {
|
||||
binary, err := Lookup()
|
||||
if err != nil {
|
||||
return fmt.Errorf("proton-drive not found in PATH: %w", err)
|
||||
}
|
||||
|
||||
parentDir := filepath.Dir(remoteDir)
|
||||
|
||||
// Try create-folder on the grandparent for the parent
|
||||
grandparent := filepath.Dir(parentDir)
|
||||
parentName := filepath.Base(parentDir)
|
||||
|
||||
cmd := exec.Command(binary, "filesystem", "create-folder", grandparent, parentName)
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = nil
|
||||
cmd.Run() // Ignore errors — folder may already exist
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UploadDir uploads an entire local directory to Proton Drive.
|
||||
// The local directory's basename becomes the remote directory name.
|
||||
func UploadDir(localDir, remoteDir string) error {
|
||||
binary, err := Lookup()
|
||||
if err != nil {
|
||||
return fmt.Errorf("proton-drive not found in PATH: %w", err)
|
||||
}
|
||||
|
||||
// Ensure parent of remote dir exists
|
||||
if err := EnsureRemoteParent(remoteDir); err != nil {
|
||||
return fmt.Errorf("cannot prepare remote directory: %w", err)
|
||||
}
|
||||
|
||||
// Upload to parent — the local dir's basename creates the remote dir
|
||||
remoteParent := filepath.Dir(remoteDir)
|
||||
|
||||
cmd := exec.Command(binary, "filesystem", "upload", localDir, remoteParent,
|
||||
"--conflict-strategy", "replace")
|
||||
|
||||
var stderr strings.Builder
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("upload to proton-drive failed: %w: %s",
|
||||
err, strings.TrimSpace(stderr.String()))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Upload uploads a single local file to a remote path on Proton Drive.
|
||||
func Upload(localPath, remotePath string) error {
|
||||
binary, err := Lookup()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user