@@ -186,17 +186,13 @@ func (k *kicRunner) Copy(f assets.CopyableFile) error {
186
186
}
187
187
}
188
188
klog .Infof ("%s (temp): %s --> %s (%d bytes)" , k .ociBin , src , dst , f .GetLength ())
189
- tmpFolder := ""
190
189
191
- // Snap only allows an application to see its own files in /tmp, making Docker unable to copy memory assets
192
- // https://github.com/kubernetes/minikube/issues/10020
193
- if isSnapBinary () {
194
- home , err := os .UserHomeDir ()
195
- if err != nil {
196
- return errors .Wrap (err , "detecting home dir" )
197
- }
198
- tmpFolder = home
190
+ isSnap := isSnapBinary ()
191
+ tmpFolder , err := tempDirectory (isSnap )
192
+ if err != nil {
193
+ return errors .Wrap (err , "determining temp directory" )
199
194
}
195
+
200
196
tf , err := ioutil .TempFile (tmpFolder , "tmpf-memory-asset" )
201
197
if err != nil {
202
198
return errors .Wrap (err , "creating temporary file" )
@@ -209,6 +205,24 @@ func (k *kicRunner) Copy(f assets.CopyableFile) error {
209
205
return k .copy (tf .Name (), dst )
210
206
}
211
207
208
+ // tempDirectory returns the directory to use as the temp directory
209
+ // or an empty string if it should use the os default temp directory.
210
+ func tempDirectory (isSnap bool ) (string , error ) {
211
+ if ! isSnap {
212
+ return "" , nil
213
+ }
214
+
215
+ // Snap only allows an application to see its own files in /tmp, making Docker unable to copy memory assets
216
+ // https://github.com/kubernetes/minikube/issues/10020
217
+
218
+ home , err := os .UserHomeDir ()
219
+ if err != nil {
220
+ return "" , errors .Wrap (err , "detecting home dir" )
221
+ }
222
+ return home , nil
223
+ }
224
+
225
+ // isSnapBinary returns true if the binary path includes "snap".
212
226
func isSnapBinary () bool {
213
227
ex , err := os .Executable ()
214
228
if err != nil {
0 commit comments