fix(app,host,macos): address PR #169 round-2 review findings
This commit is contained in:
1 parent
8d7bcd8fbd
commit
69ec8e1cbf
5 files changed
+32
-14
No files matched your search
+10
-5
@@ -116,8 +116,9 @@ type App struct {
|
||||
resolveFolderVolume func(string) (host.DirectoryVolume, error)
|
||||
imeBridge *host.IMEBridge
|
||||
|
||||
trayMgr *tray.Manager
|
||||
allowQuit bool
|
||||
trayMgr *tray.Manager
|
||||
allowQuit bool
|
||||
launchPrevDataRoot string
|
||||
quitMode string
|
||||
vmStarts sync.WaitGroup
|
||||
lastVMs []driver.VMListItem
|
||||
@@ -182,10 +183,13 @@ type Lifecycle struct {
|
||||
func New(trayIcon []byte, launch cli.WindowArgs) (*App, Lifecycle) {
|
||||
i18n.SetDetailRedactor(host.RedactText)
|
||||
cfg, needsSetup, err := config.Resolve()
|
||||
launchPrevDataRoot := ""
|
||||
if launch.DataRoot != "" {
|
||||
cfg, err = config.Load(filepath.Join(launch.DataRoot, "reims-go.json"))
|
||||
if err != nil {
|
||||
cfg = config.Default()
|
||||
} else if cfg.DataRoot != "" && !sameDataFolder(cfg.DataRoot, launch.DataRoot) {
|
||||
launchPrevDataRoot = cfg.DataRoot
|
||||
}
|
||||
cfg.DataRoot = launch.DataRoot
|
||||
needsSetup = false
|
||||
@@ -193,9 +197,10 @@ func New(trayIcon []byte, launch cli.WindowArgs) (*App, Lifecycle) {
|
||||
cfg = config.Default()
|
||||
}
|
||||
a := &App{
|
||||
cfg: cfg,
|
||||
needsSetup: needsSetup,
|
||||
launch: launch,
|
||||
cfg: cfg,
|
||||
needsSetup: needsSetup,
|
||||
launch: launch,
|
||||
launchPrevDataRoot: launchPrevDataRoot,
|
||||
trayIcon: trayIcon,
|
||||
transitions: make(map[string]string),
|
||||
pendingChanges: make(map[string][]PendingChange),
|
||||
|
||||
@@ -17,6 +17,9 @@ import (
|
||||
func (a *App) openDataRoot() dataroot.Status {
|
||||
a.mu.Lock()
|
||||
dir := a.cfg.DataRoot
|
||||
explicitLaunch := a.launch.DataRoot != ""
|
||||
prevRoot := a.launchPrevDataRoot
|
||||
a.launchPrevDataRoot = ""
|
||||
a.mu.Unlock()
|
||||
st := dataroot.Open(dir, version.Version)
|
||||
a.mu.Lock()
|
||||
@@ -24,6 +27,9 @@ func (a *App) openDataRoot() dataroot.Status {
|
||||
a.syncClipboardStagingLocked()
|
||||
a.mu.Unlock()
|
||||
a.logDataRoot(st)
|
||||
if st.Writable() && explicitLaunch {
|
||||
a.relocateRegisteredVMs(dir, prevRoot)
|
||||
}
|
||||
return st
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ func probeVulkanDevices() ([]VulkanDeviceProbe, error) {
|
||||
DeviceType: binary.LittleEndian.Uint32(propsBuf[16:20]),
|
||||
Name: cstrFromBytes(propsBuf[20:276]),
|
||||
Extensions: probeVulkanDeviceExtensions(pEnumExts, pd),
|
||||
DeviceLUID: probeVulkanDeviceLUID(pGetProps2, pd, apiVersion),
|
||||
DeviceLUID: probeVulkanDeviceLUID(pGetProps2, pd, appInfo.apiVersion, apiVersion),
|
||||
}
|
||||
out = append(out, probe)
|
||||
}
|
||||
@@ -174,8 +174,8 @@ func vulkanResultError(call string, result int32) error {
|
||||
return fmt.Errorf("%s: VkResult %d", call, result)
|
||||
}
|
||||
|
||||
func probeVulkanDeviceLUID(pGetProps2 *syscall.LazyProc, pd uintptr, apiVersion uint32) string {
|
||||
if pGetProps2 == nil || apiVersion < vkAPIVersion11 {
|
||||
func probeVulkanDeviceLUID(pGetProps2 *syscall.LazyProc, pd uintptr, instanceAPIVersion, deviceAPIVersion uint32) string {
|
||||
if pGetProps2 == nil || instanceAPIVersion < vkAPIVersion11 || deviceAPIVersion < vkAPIVersion11 {
|
||||
return ""
|
||||
}
|
||||
idProps := vkPhysicalDeviceIDProperties{
|
||||
|
||||
@@ -51,18 +51,21 @@ func cloneSSHPort(sourcePort int, reserved map[int]bool, inUse func(int) bool) (
|
||||
return 0, fmt.Errorf("no free SSH port available above %d", sourcePort)
|
||||
}
|
||||
|
||||
func reservedSSHPorts(ctx context.Context, c *reims.Client, registered []reims.VMListItem, excludeName string) map[int]bool {
|
||||
func reservedSSHPorts(ctx context.Context, c *reims.Client, registered []reims.VMListItem, excludeName string) (map[int]bool, error) {
|
||||
reserved := make(map[int]bool, len(registered))
|
||||
for _, item := range registered {
|
||||
if strings.EqualFold(item.Name, excludeName) {
|
||||
continue
|
||||
}
|
||||
det, err := c.Show(ctx, item.Name)
|
||||
if err == nil && det.SSHPort > 0 {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("inspect SSH port of registered VM %q: %w", item.Name, err)
|
||||
}
|
||||
if det.SSHPort > 0 {
|
||||
reserved[det.SSHPort] = true
|
||||
}
|
||||
}
|
||||
return reserved
|
||||
return reserved, nil
|
||||
}
|
||||
|
||||
func (d *ReimsMacOSDriver) CloneCoWWithInfo(ctx context.Context, sourceName, cloneName string, stdout, stderr io.Writer) (driver.VMInfo, error) {
|
||||
@@ -156,7 +159,11 @@ func (d *ReimsMacOSDriver) CloneCoW(ctx context.Context, sourceName, cloneName s
|
||||
}
|
||||
var clonePort int
|
||||
if src.SSHPort > 0 {
|
||||
clonePort, err = cloneSSHPort(src.SSHPort, reservedSSHPorts(ctx, c, registered, sourceName), portInUse)
|
||||
reserved, err := reservedSSHPorts(ctx, c, registered, sourceName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
clonePort, err = cloneSSHPort(src.SSHPort, reserved, portInUse)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -76,11 +76,11 @@ func writeFileAtomic(path string, data []byte, perm os.FileMode) error {
|
||||
}
|
||||
tmp := f.Name()
|
||||
defer os.Remove(tmp)
|
||||
if err := f.Chmod(perm); err != nil {
|
||||
if _, err := f.Write(data); err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
if _, err := f.Write(data); err != nil {
|
||||
if err := f.Chmod(perm); err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user