feature/taildrop: remove Close from FileOps interface (#22792) (#22794)

In PR #22749 we attempteed to clear up the casting needed for the fileOps for the close action by using the io.Closer interface. This broke the dependency to our android repo.

This change both removes this interface change that breaks compatability, and also removes the closeOps field. After further review this field was no longer necessary after we removed the persistent root behavior.

Updates tailscale/corp#51118

Change-Id: I1870030f130e92950843afb8c306b32f2008fca4

(cherry picked from commit 4ad3c29228)

Signed-off-by: Mike Jensen <mikej@tailscale.com>
Signed-off-by: Guy J Grigsby <guy@tailscale.com>
This commit is contained in:
Mike Jensen authored and Guy J Grigsby committed 2026-12-03 16:59:50 -07:00
1 parent afd4021da8
commit 5631c8b5ee
9 files changed
+4 -82

No files matched your search

+1 -8
View File
@@ -27,7 +27,6 @@ func TestDeleter(t *testing.T) {
})}
m.opts.State = must.Get(mem.New(nil, ""))
fops := must.Get(newFileOps(dir))
t.Cleanup(func() { fops.Close() })
m.opts.fileOps = fops
must.Do(m.touchFile("foo.partial"))
@@ -82,10 +81,6 @@ func TestDeleter(t *testing.T) {
m.opts.Logf = t.Logf
m.opts.Clock = tstime.DefaultClock{Clock: clock}
m.opts.State = must.Get(mem.New(nil, ""))
must.Do(fops.Close())
fops = must.Get(newFileOps(dir))
t.Cleanup(func() { fops.Close() })
m.opts.fileOps = fops
must.Do(m.opts.State.WriteState(ipn.TaildropReceivedKey, []byte{1}))
fd.Init(&m, eventHook)
defer fd.Shutdown()
@@ -157,9 +152,7 @@ func TestDeleterInitWithoutTaildrop(t *testing.T) {
var fd fileDeleter
m.opts.Logf = t.Logf
m.opts.State = must.Get(mem.New(nil, ""))
fops := must.Get(newFileOps(t.TempDir()))
t.Cleanup(func() { fops.Close() })
m.opts.fileOps = fops
m.opts.fileOps = must.Get(newFileOps(t.TempDir()))
fd.Init(&m, func(event string) { t.Errorf("unexpected event: %v", event) })
fd.Shutdown()
}
-10
View File
@@ -95,7 +95,6 @@ type Extension struct {
capFileSharing bool
fileWaiters set.HandleSet[context.CancelFunc] // of wake-up funcs
mgr atomic.Pointer[manager] // mutex held to write; safe to read without lock;
closeOps io.Closer // extension-owned fileOps, closed on manager replacement or shutdown
// outgoingFiles keeps track of Taildrop outgoing files keyed to their OutgoingFile.ID
outgoingFiles map[string]*ipn.OutgoingFile
}
@@ -145,12 +144,6 @@ func (e *Extension) setMgrLocked(mgr *manager) {
if old := e.mgr.Swap(mgr); old != nil {
old.Shutdown()
}
if closeOps := e.closeOps; closeOps != nil {
e.closeOps = nil
if err := closeOps.Close(); err != nil {
e.logf("closing file storage: %v", err)
}
}
}
func (e *Extension) onChangeProfile(profile ipn.LoginProfileView, _ ipn.PrefsView, sameNode bool) {
@@ -200,9 +193,6 @@ func (e *Extension) onChangeProfile(profile ipn.LoginProfileView, _ ipn.PrefsVie
fileOps: fops,
SendFileNotify: e.sendFileNotify,
}.New())
if e.fileOps == nil {
e.closeOps = fops
}
}
// fileRoot returns where to store Taildrop files for the given user and whether
-3
View File
@@ -36,9 +36,6 @@ type FileOps interface {
// OpenReader opens the given basename for the given name or an error.
OpenReader(name string) (io.ReadCloser, error)
// Close releases any resources held by the receiver.
io.Closer
}
var newFileOps func(dir string) (FileOps, error)
-4
View File
@@ -257,10 +257,6 @@ func (f *fsFileOps) OpenReader(name string) (io.ReadCloser, error) {
return root.Open(filepath.Base(path))
}
func (f *fsFileOps) Close() error {
return nil
}
// joinDir is like [filepath.Join] but returns an error if baseName is too long,
// is a relative path instead of a basename, or is otherwise invalid or unsafe for incoming files.
func joinDir(dir, baseName string) (string, error) {
-8
View File
@@ -39,7 +39,6 @@ func TestFSFileOpsSymlinkConfinement(t *testing.T) {
fops, err := newFileOps(root)
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, fops.Close()) })
_, _, err = fops.OpenWriter("file.partial", 0, 0o600)
require.Error(t, err)
@@ -63,7 +62,6 @@ func TestOpenWriterRootSwap(t *testing.T) {
require.NoError(t, os.Mkdir(outside, 0o700))
fops, err := newFileOps(root)
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, fops.Close()) })
require.NoError(t, os.Remove(root))
mustSymlink(t, outside, root)
@@ -82,7 +80,6 @@ func TestOpenWriterResumeSymlink(t *testing.T) {
fops, err := newFileOps(root)
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, fops.Close()) })
_, _, err = fops.OpenWriter("file.partial", 2, 0o600)
require.Error(t, err)
@@ -116,7 +113,6 @@ func TestRenameSymlink(t *testing.T) {
fops, err := newFileOps(root)
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, fops.Close()) })
_, err = fops.Rename(filepath.Join(root, "file.partial"), "file")
require.Error(t, err)
@@ -135,7 +131,6 @@ func TestRenameOutsideRoot(t *testing.T) {
require.NoError(t, os.WriteFile(outside, []byte("content"), 0o600))
fops, err := newFileOps(root)
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, fops.Close()) })
_, err = fops.Rename(outside, "file")
require.Error(t, err)
@@ -152,7 +147,6 @@ func TestOpenReaderSymlink(t *testing.T) {
mustSymlink(t, outside, filepath.Join(root, "file"))
fops, err := newFileOps(root)
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, fops.Close()) })
_, err = fops.OpenReader("file")
require.Error(t, err)
@@ -168,7 +162,6 @@ func TestOpenWriterInRootSymlink(t *testing.T) {
mustSymlink(t, "target", filepath.Join(root, "file.partial"))
fops, err := newFileOps(root)
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, fops.Close()) })
w, path, err := fops.OpenWriter("file.partial", 2, 0o600)
require.NoError(t, err)
@@ -188,7 +181,6 @@ func TestFSFileOpsRootRecreated(t *testing.T) {
root := filepath.Join(t.TempDir(), "Taildrop")
fops, err := newFileOps(root)
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, fops.Close()) })
require.NoError(t, os.RemoveAll(root))
+1 -4
View File
@@ -491,7 +491,6 @@ func TestHandlePeerAPI(t *testing.T) {
if fo, err = newFileOps(t.TempDir()); err != nil {
t.Fatalf("newFileOps: %v", err)
}
t.Cleanup(func() { fo.Close() })
}
var e peerAPITestEnv
@@ -543,11 +542,9 @@ func TestHandlePeerAPI(t *testing.T) {
// a bit. So test that we work around that sufficiently.
func TestFileDeleteRace(t *testing.T) {
dir := t.TempDir()
fops := must.Get(newFileOps(dir))
t.Cleanup(func() { fops.Close() })
taildropMgr := managerOptions{
Logf: t.Logf,
fileOps: fops,
fileOps: must.Get(newFileOps(dir)),
}.New()
t.Cleanup(taildropMgr.Shutdown)
+1 -3
View File
@@ -22,9 +22,7 @@ func TestResume(t *testing.T) {
dir := t.TempDir()
fops := must.Get(newFileOps(dir))
t.Cleanup(func() { fops.Close() })
m := managerOptions{Logf: t.Logf, fileOps: fops}.New()
m := managerOptions{Logf: t.Logf, fileOps: must.Get(newFileOps(dir))}.New()
t.Cleanup(m.Shutdown)
rn := rand.New(rand.NewSource(0))
+1 -4
View File
@@ -30,7 +30,6 @@ func TestPutFileSymlink(t *testing.T) {
t.Skipf("cannot create symlinks: %v", err)
}
fops := must.Get(newFileOps(dir))
t.Cleanup(func() { fops.Close() })
mgr := managerOptions{Logf: t.Logf, fileOps: fops, DirectFileMode: true}.New()
t.Cleanup(mgr.Shutdown)
@@ -62,13 +61,11 @@ func TestPutFile(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dir := t.TempDir()
fops := must.Get(newFileOps(dir))
t.Cleanup(func() { fops.Close() })
mgr := managerOptions{
Logf: t.Logf,
Clock: tstime.DefaultClock{},
State: nil,
fileOps: fops,
fileOps: must.Get(newFileOps(dir)),
DirectFileMode: tt.directFileMode,
SendFileNotify: func() {},
}.New()
-38
View File
@@ -38,44 +38,6 @@ func TestNextFilename(t *testing.T) {
}
}
type closeTrackingFileOps struct {
FileOps
closed bool
}
func (f *closeTrackingFileOps) Close() error {
f.closed = true
return nil
}
func TestExtensionFileOpsClose(t *testing.T) {
t.Parallel()
fops, err := newFileOps(t.TempDir())
if err != nil {
t.Fatal(err)
}
e := &Extension{logf: t.Logf, closeOps: fops}
if err := e.Shutdown(); err != nil {
t.Fatal(err)
}
if err := e.Shutdown(); err != nil {
t.Fatal(err)
}
if _, err := fops.Stat("file"); err == nil {
t.Fatal("Stat succeeded after Extension.Shutdown closed FileOps")
}
injected := &closeTrackingFileOps{}
e = &Extension{logf: t.Logf, fileOps: injected}
if err := e.Shutdown(); err != nil {
t.Fatal(err)
}
if injected.closed {
t.Fatal("Extension closed injected FileOps")
}
}
func TestValidateBaseName(t *testing.T) {
tests := []struct {
in string