1
0
mirror of https://github.com/lxc/incus.git synced 2026-02-05 09:46:19 +01:00

client: Add configurable temp directory

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
This commit is contained in:
Stéphane Graber
2025-07-31 00:55:40 -04:00
parent c30da7e941
commit a83e437873
7 changed files with 22 additions and 7 deletions

View File

@@ -68,6 +68,9 @@ type ConnectionArgs struct {
// Caching support for image servers
CachePath string
CacheExpiry time.Duration
// Temp storage.
TempPath string
}
// ConnectIncus lets you connect to a remote Incus daemon over HTTPs.
@@ -129,6 +132,7 @@ func ConnectIncusHTTPWithContext(ctx context.Context, args *ConnectionArgs, clie
eventConns: make(map[string]*websocket.Conn),
eventListeners: make(map[string][]*EventListener),
skipEvents: args.SkipGetEvents,
tempPath: args.TempPath,
}
// Setup the HTTP client
@@ -218,6 +222,7 @@ func ConnectIncusUnixWithContext(ctx context.Context, path string, args *Connect
eventListeners: make(map[string][]*EventListener),
skipEvents: args.SkipGetEvents,
project: projectName,
tempPath: args.TempPath,
}
// Setup the HTTP client
@@ -280,6 +285,7 @@ func ConnectSimpleStreams(uri string, args *ConnectionArgs) (ImageServer, error)
httpHost: uri,
httpUserAgent: args.UserAgent,
httpCertificate: args.TLSServerCert,
tempPath: args.TempPath,
}
// Setup the HTTP client
@@ -341,7 +347,8 @@ func ConnectOCI(uri string, args *ConnectionArgs) (ImageServer, error) {
httpUserAgent: args.UserAgent,
httpCertificate: args.TLSServerCert,
cache: map[string]ociInfo{},
cache: map[string]ociInfo{},
tempPath: args.TempPath,
}
// Setup the HTTP client
@@ -381,6 +388,7 @@ func httpsIncus(ctx context.Context, requestURL string, args *ConnectionArgs) (I
eventConns: make(map[string]*websocket.Conn),
eventListeners: make(map[string][]*EventListener),
skipEvents: args.SkipGetEvents,
tempPath: args.TempPath,
}
if slices.Contains([]string{api.AuthenticationMethodOIDC}, args.AuthType) {
@@ -409,5 +417,6 @@ func httpsIncus(ctx context.Context, requestURL string, args *ConnectionArgs) (I
return nil, err
}
}
return &server, nil
}

View File

@@ -54,6 +54,8 @@ type ProtocolIncus struct {
project string
oidcClient *oidcClient
tempPath string
}
// Disconnect gets rid of any background goroutines.

View File

@@ -832,14 +832,14 @@ func (r *ProtocolIncus) CopyImage(source ImageServer, image api.Image, args *Ima
// Relay mode
if args != nil && args.Mode == "relay" {
metaFile, err := os.CreateTemp("", "incus_image_")
metaFile, err := os.CreateTemp(r.tempPath, "incus_image_")
if err != nil {
return nil, err
}
defer func() { _ = os.Remove(metaFile.Name()) }()
rootfsFile, err := os.CreateTemp("", "incus_image_")
rootfsFile, err := os.CreateTemp(r.tempPath, "incus_image_")
if err != nil {
return nil, err
}

View File

@@ -14,6 +14,8 @@ type ProtocolOCI struct {
// Cache for images.
cache map[string]ociInfo
tempPath string
}
// Disconnect is a no-op for OCI.

View File

@@ -144,7 +144,7 @@ func (r *ProtocolOCI) GetImageFile(fingerprint string, req ImageFileRequest) (*I
}
// Get some temporary storage.
ociPath, err := os.MkdirTemp("", "incus-oci-")
ociPath, err := os.MkdirTemp(r.tempPath, "incus-oci-")
if err != nil {
return nil, err
}
@@ -352,7 +352,7 @@ func (r *ProtocolOCI) runSkopeo(action string, image string, args ...string) (st
return "", err
}
authFile, err := os.CreateTemp("", "incus_client_auth_")
authFile, err := os.CreateTemp(r.tempPath, "incus_client_auth_")
if err != nil {
return "", err
}

View File

@@ -15,6 +15,8 @@ type ProtocolSimpleStreams struct {
httpHost string
httpUserAgent string
httpCertificate string
tempPath string
}
// Disconnect is a no-op for simplestreams.

View File

@@ -163,7 +163,7 @@ func (r *ProtocolSimpleStreams) GetImageFile(fingerprint string, req ImageFileRe
if err == nil && req.DeltaSourceRetriever != nil {
applyDelta := func(file simplestreams.DownloadableFile, srcPath string, target io.Writer) (int64, error) {
// Create temporary file for the delta
deltaFile, err := os.CreateTemp("", "incus_image_")
deltaFile, err := os.CreateTemp(r.tempPath, "incus_image_")
if err != nil {
return -1, err
}
@@ -179,7 +179,7 @@ func (r *ProtocolSimpleStreams) GetImageFile(fingerprint string, req ImageFileRe
}
// Create temporary file for the delta
patchedFile, err := os.CreateTemp("", "incus_image_")
patchedFile, err := os.CreateTemp(r.tempPath, "incus_image_")
if err != nil {
return -1, err
}