forked from rancher-sandbox/rancher-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rdctl: Use new function when terminating RD for factory-reset
Since we needed a generalized function to deal with terminating extensions, we might as well re-use it for terminating the process for the rest of factory reset. Signed-off-by: Mark Yen <mark.yen@suse.com>
- Loading branch information
Showing
12 changed files
with
169 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright © 2024 SUSE LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package directories | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
) | ||
|
||
// GetApplicationDirectory returns the installation directory of the application. | ||
func GetApplicationDirectory() (string, error) { | ||
exePathWithSymlinks, err := os.Executable() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
exePath, err := filepath.EvalSymlinks(exePathWithSymlinks) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
platform := runtime.GOOS | ||
if runtime.GOOS == "windows" { | ||
// On Windows, we use "win32" instead of "windows". | ||
platform = "win32" | ||
} | ||
|
||
// Given the path to the exe, find its directory, and drop the | ||
// "resources\win32\bin" suffix (possibly with another "resources" in front). | ||
// On mac, we need to drop "Contents/Resources/resources/darwin/bin". | ||
resultDir := filepath.Dir(exePath) | ||
for _, part := range []string{"bin", platform, "resources", "Resources", "Contents"} { | ||
for filepath.Base(resultDir) == part { | ||
resultDir = filepath.Dir(resultDir) | ||
} | ||
} | ||
return resultDir, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright © 2024 SUSE LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package directories_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/rancher-sandbox/rancher-desktop/src/go/rdctl/pkg/directories" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetApplicationDirectory(t *testing.T) { | ||
_, err := directories.GetApplicationDirectory() | ||
assert.NoError(t, err) | ||
// `go test` makes a temporary directory, so we can't sensibly test the | ||
// return value. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.