fix(clipboard): align Guest Tools v14 changelog and rebind staging dir after setup
This commit is contained in:
1 parent
f6989a40f7
commit
8c823d98fb
5 files changed
+134
-10
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"group": "new",
|
||||
"order": 70,
|
||||
"authors": ["yxc0915"],
|
||||
"zh": "剪贴板互通支持在 Windows 与 macOS 之间双向复制粘贴文件与文件夹,宿主到虚拟机按需只读挂载免预拷贝,虚拟机到宿主默认限制单次 `128 MB`(可在插件设置中于 `1–512 MB` 间调节),已安装的虚拟机需更新至第 13 版 Guest Tools。",
|
||||
"en": "Sync copied files and folders both ways in Clipboard Sync, mounting on demand from Windows to macOS without pre-copying and capping macOS-to-Windows transfers at `128 MB` by default (adjustable from `1` to `512 MB` in plugin settings); installed VMs require Guest Tools v13."
|
||||
"authors": ["staytomorrow"],
|
||||
"zh": "剪贴板互通支持在 Windows 与 macOS 之间双向复制粘贴文件与文件夹,宿主到虚拟机按需只读挂载免预拷贝,虚拟机到宿主默认限制单次 `128 MB`(可在插件设置中于 `1–512 MB` 间调节),已安装的虚拟机需更新至第 14 版 Guest Tools。",
|
||||
"en": "Sync copied files and folders both ways in Clipboard Sync, mounting on demand from Windows to macOS without pre-copying and capping macOS-to-Windows transfers at `128 MB` by default (adjustable from `1` to `512 MB` in plugin settings); installed VMs require Guest Tools v14."
|
||||
}
|
||||
@@ -108,9 +108,6 @@ func (a *App) startGuestToolsServer() (srv *guesttools.Server, port int, created
|
||||
} else {
|
||||
srv = guesttools.NewServer(nil)
|
||||
}
|
||||
if a.cfg != nil && a.cfg.DataRoot != "" && !a.needsSetup && !a.root.ReadOnly {
|
||||
srv.SetClipStagingDir(filepath.Join(a.cfg.TempDir(), "clip-files"))
|
||||
}
|
||||
srv.SetHostDropHandler(a.handleHostDrop)
|
||||
srv.SetDropAckHandler(a.handleHostDropAck)
|
||||
srv.SetDropPasteHandler(a.handleHostDropPaste)
|
||||
@@ -128,7 +125,12 @@ func (a *App) startGuestToolsServer() (srv *guesttools.Server, port int, created
|
||||
srv.SetStatusChangeHandler(func(string) { a.syncKeymapRules() })
|
||||
created = true
|
||||
}
|
||||
stagingDir := ""
|
||||
if a.cfg != nil && a.cfg.DataRoot != "" && !a.needsSetup && !a.root.ReadOnly {
|
||||
stagingDir = filepath.Join(a.cfg.TempDir(), "clip-files")
|
||||
}
|
||||
a.mu.Unlock()
|
||||
srv.SetClipStagingDir(stagingDir)
|
||||
|
||||
port, err = srv.Start(guesttools.DefaultPort)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -73,3 +79,99 @@ func TestGuestToolsBridgeFollowsPluginSwitch(t *testing.T) {
|
||||
t.Fatal("plugin switched back off: Guest Tools still reported as available")
|
||||
}
|
||||
}
|
||||
|
||||
type stubFileClip struct {
|
||||
files []string
|
||||
seq uint32
|
||||
}
|
||||
|
||||
func (c *stubFileClip) ReadText() (string, error) { return "", nil }
|
||||
func (c *stubFileClip) WriteText(string) error { c.seq++; return nil }
|
||||
func (c *stubFileClip) WritePNG([]byte) error { c.seq++; return nil }
|
||||
func (c *stubFileClip) SequenceNumber() uint32 { return c.seq }
|
||||
func (c *stubFileClip) WriteFiles(p []string) error { c.files = p; c.seq++; return nil }
|
||||
func (c *stubFileClip) Read() (guesttools.ClipPayload, error) {
|
||||
if len(c.files) > 0 {
|
||||
return guesttools.ClipPayload{Kind: guesttools.ClipFiles, Files: c.files}, nil
|
||||
}
|
||||
return guesttools.ClipPayload{}, nil
|
||||
}
|
||||
|
||||
// Completing first-run setup without restarting must bind the clipboard file
|
||||
// staging directory on the existing Server so guest-to-host file uploads do not
|
||||
// fail with 503.
|
||||
func TestGuestToolsServerConfiguresClipStagingAfterSetup(t *testing.T) {
|
||||
suggestedDir := t.TempDir()
|
||||
chosenDir := t.TempDir()
|
||||
cfg := config.Default()
|
||||
cfg.DataRoot = suggestedDir
|
||||
clip := &stubFileClip{seq: 1}
|
||||
srv := guesttools.NewServer(clip)
|
||||
a := &App{cfg: cfg, needsSetup: true, guestTools: srv}
|
||||
defer func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
_ = srv.Close(ctx)
|
||||
}()
|
||||
|
||||
_, port, _, err := a.startGuestToolsServer()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tok := "tok-setup-transition-000000000000000"
|
||||
srv.RegisterVM(guesttools.VMConfig{VMName: "mac", Token: tok})
|
||||
|
||||
var tarBuf bytes.Buffer
|
||||
tw := tar.NewWriter(&tarBuf)
|
||||
content := []byte("after-setup")
|
||||
if err := tw.WriteHeader(&tar.Header{Name: "doc.txt", Typeflag: tar.TypeReg, Mode: 0o644, Size: int64(len(content))}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _ = tw.Write(content)
|
||||
_ = tw.Close()
|
||||
|
||||
postTar := func() int {
|
||||
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("http://127.0.0.1:%d/v1/clipboard", port), bytes.NewReader(tarBuf.Bytes()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+tok)
|
||||
req.Header.Set("Content-Type", "application/x-tar")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = resp.Body.Close()
|
||||
return resp.StatusCode
|
||||
}
|
||||
|
||||
if code := postTar(); code != http.StatusServiceUnavailable {
|
||||
t.Fatalf("before setup completion: got %d, want 503", code)
|
||||
}
|
||||
if entries := dirEntries(t, suggestedDir); len(entries) != 0 {
|
||||
t.Fatalf("suggested folder written before setup: %v", entries)
|
||||
}
|
||||
|
||||
// Simulate finishing first-run setup onto chosenDir without restarting.
|
||||
a.mu.Lock()
|
||||
a.cfg.DataRoot = chosenDir
|
||||
a.needsSetup = false
|
||||
a.root.ReadOnly = false
|
||||
a.mu.Unlock()
|
||||
if _, _, _, err := a.startGuestToolsServer(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if code := postTar(); code != http.StatusOK {
|
||||
t.Fatalf("after setup completion without restart: got %d, want 200", code)
|
||||
}
|
||||
if len(clip.files) != 1 {
|
||||
t.Fatalf("expected 1 unpacked clipboard file, got %v", clip.files)
|
||||
}
|
||||
if got, err := os.ReadFile(clip.files[0]); err != nil || string(got) != "after-setup" {
|
||||
t.Fatalf("unpacked file content = %q, err=%v", got, err)
|
||||
}
|
||||
if !strings.HasPrefix(clip.files[0], filepath.Join(chosenDir, "tmp", "clip-files")) {
|
||||
t.Fatalf("unpacked file path %q outside chosen DataRoot", clip.files[0])
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,10 @@ func (s *Server) SetClipStagingDir(dir string) {
|
||||
}
|
||||
s.mu.Lock()
|
||||
old := s.clipStagingDir
|
||||
if old == clean {
|
||||
s.mu.Unlock()
|
||||
return
|
||||
}
|
||||
s.clipStagingDir = clean
|
||||
s.clipGuestBatches = make(map[string][]clipGuestBatch)
|
||||
s.mu.Unlock()
|
||||
|
||||
@@ -908,6 +908,16 @@ func (m *Manager) stateNotLoadedErr() error {
|
||||
|
||||
// --- Settings store (app-scoped & vm-scoped, hiding x-secret on readback) ---
|
||||
|
||||
func settingAllowsBothScopes(schema *SettingsSchema, key string) bool {
|
||||
if schema == nil {
|
||||
return false
|
||||
}
|
||||
if prop, ok := schema.Properties[key]; ok && prop.Scope != "" {
|
||||
return prop.Scope == "both"
|
||||
}
|
||||
return schema.Scope == "both"
|
||||
}
|
||||
|
||||
func (m *Manager) GetSettings(pluginID, vmName string, maskSecrets bool) map[string]any {
|
||||
var schema *SettingsSchema
|
||||
if info, ok := m.registry.Info(pluginID); ok {
|
||||
@@ -926,10 +936,16 @@ func (m *Manager) GetSettings(pluginID, vmName string, maskSecrets bool) map[str
|
||||
}
|
||||
if m.state != nil {
|
||||
if rec := m.state.Plugins[pluginID]; rec != nil {
|
||||
for k, v := range rec.AppSettings {
|
||||
out[k] = v
|
||||
}
|
||||
if vmName != "" {
|
||||
if vmName == "" {
|
||||
for k, v := range rec.AppSettings {
|
||||
out[k] = v
|
||||
}
|
||||
} else {
|
||||
for k, v := range rec.AppSettings {
|
||||
if settingAllowsBothScopes(schema, k) {
|
||||
out[k] = v
|
||||
}
|
||||
}
|
||||
if vmMap := rec.VMSettings[vmName]; vmMap != nil {
|
||||
for k, v := range vmMap {
|
||||
out[k] = v
|
||||
|
||||
Reference in new issue
Block a user