Skip to content

Commit

Permalink
fixed some minor issue
Browse files Browse the repository at this point in the history
- Fixed an issue where the clone copy would not always be used
- Fixed an issue where the telemetry could generate a nil pointer issue
- Fixed an issue where the pull file would still need the provider even if not needed
- Fixed an issue where the db was being saved more often that needed
  • Loading branch information
cjlapao committed Oct 17, 2024
1 parent d3bc93d commit 7216904
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (c *Config) DbBackupInterval() time.Duration {
func (c *Config) DbSaveInterval() time.Duration {
interval := c.GetIntKey(constants.DATABASE_SAVE_INTERVAL_ENV_VAR)
if interval == 0 {
return 30 * time.Second
return 2 * time.Minute
}

return time.Duration(interval) * time.Minute
Expand Down
65 changes: 56 additions & 9 deletions src/helpers/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"syscall"
"time"

"github.com/briandowns/spinner"
Expand Down Expand Up @@ -331,6 +331,34 @@ func FileExists(path string) bool {
return true
}

func extractVolumeName(path string) (string, error) {
if runtime.GOOS == "windows" {
return "", fmt.Errorf("not supported on windows")
}
if runtime.GOOS == "linux" {
return "", fmt.Errorf("not supported on linux")
}

if !strings.HasPrefix(path, "/Volumes/") {
volume := filepath.Dir(path)
return volume, nil
}

// Clean up the path to remove any redundant separators
cleanedPath := filepath.Clean(path)

// Split the path into parts based on the separator
parts := strings.Split(cleanedPath, string(filepath.Separator))

// Check if the path has enough parts to contain a volume name
if len(parts) < 3 || parts[1] != "Volumes" {
return "", fmt.Errorf("invalid path or volume not found in path: %s", path)
}

// Return the volume name (third part in the split path)
return fmt.Sprintf("/%s/%s", parts[1], parts[2]), nil
}

// CopyDir recursively copies a directory tree, attempting to preserve permissions.
// Source directory must exist, destination directory must *not* exist.
// Symlinks are ignored and skipped.
Expand Down Expand Up @@ -365,16 +393,36 @@ func CopyDir(src string, dst string) (err error) {
}

// fmt.Printf("Copying folder with macos clone %s, %s\n", src, dst)
cmd := Command{
Command: "cp",
Args: []string{"-c", "-r", src, dst},
}
var cmd Command
// if the destination is a mounted volume, we cannot use the clone command
if strings.HasPrefix(dst, "/Volumes") && !strings.HasPrefix(src, "/Volumes") {
srcVolumeName, err := extractVolumeName(src)
if err != nil {
return err
}
dstVolumeName, err := extractVolumeName(dst)
if err != nil {
return err
}

srcInfo, err := os.Stat(srcVolumeName)
if err != nil {
return err
}
dstInfo, err := os.Stat(dstVolumeName)
if err != nil && !os.IsNotExist(err) {
return err
}

if os.IsNotExist(err) || srcInfo.Sys().(*syscall.Stat_t).Dev != dstInfo.Sys().(*syscall.Stat_t).Dev {
cmd = Command{
Command: "cp",
Args: []string{"-r", src, dst},
}
} else {
cmd = Command{
Command: "cp",
Args: []string{"-c", "-r", src, dst},
}
}

if _, err := ExecuteWithNoOutput(context.TODO(), cmd, 2*time.Hour); err != nil {
Expand All @@ -384,15 +432,14 @@ func CopyDir(src string, dst string) (err error) {
return nil
}

println("passed")
if FileExists(src) {
err = os.MkdirAll(dst, si.Mode())
if err != nil {
return err
}
}

entries, err := ioutil.ReadDir(src)
entries, err := os.ReadDir(src)
if err != nil {
return err
}
Expand All @@ -408,7 +455,7 @@ func CopyDir(src string, dst string) (err error) {
}
} else {
// Skip symlinks.
if entry.Mode()&os.ModeSymlink != 0 {
if entry.Type()&os.ModeSymlink != 0 {
continue
}

Expand Down
2 changes: 0 additions & 2 deletions src/pdfile/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ func (p *PDFileService) Validate() *diagnostics.PDFileDiagnostics {
}
} else {
if runCMD == "push" ||
runCMD == "pull" ||
runCMD == "delete" ||
runCMD == "import" ||
runCMD == "list" {
diag.AddError(fmt.Errorf("provider command not found"))
Expand Down
6 changes: 6 additions & 0 deletions src/telemetry/telemetry_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ func (t *TelemetryService) Callback(result types.ExecuteResult) {
}

func (t *TelemetryService) Flush() {
if t.client == nil {
return
}
t.client.Flush()
}

func (t *TelemetryService) Close() {
if t.client == nil {
return
}
t.client.Shutdown()
}

0 comments on commit 7216904

Please sign in to comment.