From 1c994c86c1f83c24de2e21b6267b3730bc4b6beb Mon Sep 17 00:00:00 2001 From: abe-winter Date: Tue, 14 Jan 2025 16:30:07 -0500 Subject: [PATCH] APP-7377 registry modules on windows (#4702) --- robot/packages/cloud_package_manager.go | 4 ++++ robot/packages/utils.go | 17 ++++++++++++++++- robot/web/web.go | 3 ++- utils/env.go | 6 ++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/robot/packages/cloud_package_manager.go b/robot/packages/cloud_package_manager.go index 8ef8a227d1e..96e7a69ed19 100644 --- a/robot/packages/cloud_package_manager.go +++ b/robot/packages/cloud_package_manager.go @@ -12,6 +12,7 @@ import ( "net/url" "os" "path/filepath" + "runtime" "strings" "sync" "time" @@ -238,6 +239,9 @@ func (m *cloudManager) validateAndGetChangedPackages( // Cleanup removes all unknown packages from the working directory. func (m *cloudManager) Cleanup(ctx context.Context) error { + if runtime.GOOS == "windows" { //nolint:goconst + return nil + } // Only allow one rdk process to operate on the manager at once. This is generally safe to keep locked for an extended period of time // since the config reconfiguration process is handled by a single thread. m.mu.Lock() diff --git a/robot/packages/utils.go b/robot/packages/utils.go index 577ffcad7c2..4725004857d 100644 --- a/robot/packages/utils.go +++ b/robot/packages/utils.go @@ -11,6 +11,7 @@ import ( "io/fs" "os" "path/filepath" + "runtime" "strings" "time" @@ -85,7 +86,16 @@ func installPackage( return err } - err = os.Rename(tmpDataPath, p.LocalDataDirectory(packagesDir)) + renameDest := p.LocalDataDirectory(packagesDir) + if runtime.GOOS == "windows" { + if _, err := os.Stat(renameDest); err == nil { + logger.Debug("package rename destination exists, deleting") + if err := os.RemoveAll(renameDest); err != nil { + logger.Warnf("ignoring error from removing rename dest %s", err) + } + } + } + err = os.Rename(tmpDataPath, renameDest) if err != nil { utils.UncheckedError(cleanup(packagesDir, p)) return err @@ -381,6 +391,11 @@ func readStatusFile(pkg config.PackageConfig, packagesDir string) (packageSyncFi func writeStatusFile(pkg config.PackageConfig, statusFile packageSyncFile, packagesDir string) error { syncFileName := getSyncFileName(pkg.LocalDataDirectory(packagesDir)) + if runtime.GOOS == "windows" { + if err := os.MkdirAll(pkg.LocalDataDirectory(packagesDir), os.ModeDir); err != nil { + return err + } + } statusFileBytes, err := json.MarshalIndent(statusFile, "", " ") if err != nil { diff --git a/robot/web/web.go b/robot/web/web.go index f412ec4cedc..dbf5ae4a713 100644 --- a/robot/web/web.go +++ b/robot/web/web.go @@ -44,7 +44,8 @@ import ( // SubtypeName is a constant that identifies the internal web resource subtype string. const ( - SubtypeName = "web" + SubtypeName = "web" + // TCPParentPort is the port of the parent socket when VIAM_TCP_MODE is set. TCPParentPort = 14998 // TestTCPParentPort is the test suite version of TCPParentPort. It's different to avoid // collisions; it's listed here for documentation. diff --git a/utils/env.go b/utils/env.go index 3e01d4a587c..0d872ad9287 100644 --- a/utils/env.go +++ b/utils/env.go @@ -69,6 +69,12 @@ func PlatformHomeDir() string { if runtime.GOOS == "android" { return AndroidFilesDir } + if runtime.GOOS == "windows" { + homedir, _ := os.UserHomeDir() //nolint:errcheck + if homedir != "" { + return homedir + } + } return os.Getenv("HOME") }