tq: drop unused ClearTempStorage adapter method

The ClearTempStorage() method of the transfer Adapter interface,
while implemented for most adapters, is never actually called,
and moreover is dangerous in some its current implementations
if it were ever to be called.

Specifically in the basic upload and download adapters and the
SSH adapter, the ClearTempStorage() method relies on an internal
tempDir() method to return the path to the temporary directory
to be cleared, which ClearTempStorage() then removes entirely.

The tempDir() methods, however, can return os.TempDir() if they
are unable to create a local temporary directory within the
Git LFS storage directory, and also do not cache the path to
the directory they first returned.  So were ClearTempStorage()
ever to be called in one of these adapters, its invocation of
tempDir() might just return the system temporary directory
(e.g., /tmp on Unix), which it would then attempt to remove.

The ClearTempStorage() method was introduced in commits
f124f0585f73279195cb20ecb4aa9e149512b48a and
940a91a8df18eaf16e9a0162999f26d59fa9f5af of PR #1265, but
has never been called by any user of the transfer
adapter interface.

We therefore just remove this method and its implemetations
from all the current tranfer adapters.
This commit is contained in:
Chris Darroch 2021-07-20 23:51:32 -04:00
parent 946f6cc4a6
commit e1624ca685
7 changed files with 1 additions and 33 deletions

@ -20,10 +20,6 @@ type basicDownloadAdapter struct {
*adapterBase
}
func (a *basicDownloadAdapter) ClearTempStorage() error {
return os.RemoveAll(a.tempDir())
}
func (a *basicDownloadAdapter) tempDir() string {
// Shared with the SSH adapter.
d := filepath.Join(a.fs.LFSStorageDir, "incomplete")

@ -25,13 +25,8 @@ type basicUploadAdapter struct {
*adapterBase
}
func (a *basicUploadAdapter) ClearTempStorage() error {
// Should be empty already but also remove dir
return os.RemoveAll(a.tempDir())
}
func (a *basicUploadAdapter) tempDir() string {
// Must be dedicated to this adapter as deleted by ClearTempStorage
// Dedicated to this adapter rather than shared with basic download.
d := filepath.Join(os.TempDir(), "git-lfs-basic-temp")
if err := tools.MkdirAll(d, a.fs); err != nil {
return os.TempDir()

@ -119,11 +119,6 @@ func (a *customAdapter) Begin(cfg AdapterConfig, cb ProgressCallback) error {
return a.adapterBase.Begin(&customAdapterConfig{AdapterConfig: cfg}, cb)
}
func (a *customAdapter) ClearTempStorage() error {
// no action required
return nil
}
func (a *customAdapter) WorkerStarting(workerNum int) (interface{}, error) {
// Start a process per worker
// If concurrent = false we have already dialled back workers to 1

@ -380,12 +380,6 @@ func (a *SSHAdapter) Begin(cfg AdapterConfig, cb ProgressCallback) error {
return nil
}
// ClearTempStorage clears any temporary files, such as unfinished downloads that
// would otherwise be resumed
func (a *SSHAdapter) ClearTempStorage() error {
return os.RemoveAll(a.tempDir())
}
func (a *SSHAdapter) Trace(format string, args ...interface{}) {
if !a.adapterBase.debugging {
return

@ -245,9 +245,6 @@ type Adapter interface {
// once the queued items have completed.
// This call blocks until all items have been processed
End()
// ClearTempStorage clears any temporary files, such as unfinished downloads that
// would otherwise be resumed
ClearTempStorage() error
}
// Result of a transfer returned through CompletionChannel()

@ -33,10 +33,6 @@ func (a *testAdapter) Add(ts ...*Transfer) (retries <-chan TransferResult) {
func (a *testAdapter) End() {
}
func (a *testAdapter) ClearTempStorage() error {
return nil
}
func newTestAdapter(name string, dir Direction) Adapter {
return &testAdapter{name, dir}
}

@ -23,11 +23,6 @@ type tusUploadAdapter struct {
*adapterBase
}
func (a *tusUploadAdapter) ClearTempStorage() error {
// nothing to do, all temp state is on the server end
return nil
}
func (a *tusUploadAdapter) WorkerStarting(workerNum int) (interface{}, error) {
return nil, nil
}