@@ -197,7 +197,7 @@ func (ic *ContainerEngine) QuadletInstall(ctx context.Context, pathsOrURLs []str
197
197
installReport .QuadletErrors [toInstall ] = fmt .Errorf ("populating temporary file: %w" , err )
198
198
continue
199
199
}
200
- installedPath , err := ic .installQuadlet (ctx , tmpFile .Name (), quadletFileName , installDir , assetFile , validateQuadletFile )
200
+ installedPath , err := ic .installQuadlet (ctx , tmpFile .Name (), quadletFileName , installDir , assetFile , validateQuadletFile , options . Force )
201
201
if err != nil {
202
202
installReport .QuadletErrors [toInstall ] = err
203
203
continue
@@ -210,7 +210,7 @@ func (ic *ContainerEngine) QuadletInstall(ctx context.Context, pathsOrURLs []str
210
210
continue
211
211
}
212
212
// If toInstall is a single file, execute the original logic
213
- installedPath , err := ic .installQuadlet (ctx , toInstall , "" , installDir , assetFile , validateQuadletFile )
213
+ installedPath , err := ic .installQuadlet (ctx , toInstall , "" , installDir , assetFile , validateQuadletFile , options . Force )
214
214
if err != nil {
215
215
installReport .QuadletErrors [toInstall ] = err
216
216
continue
@@ -254,7 +254,7 @@ func getFileName(resp *http.Response, fileURL string) (string, error) {
254
254
// Perform some minimal validation, but not much.
255
255
// We can't know about a lot of problems without running the Quadlet binary, which we
256
256
// only want to do once.
257
- func (ic * ContainerEngine ) installQuadlet (_ context.Context , path , destName , installDir , assetFile string , isQuadletFile bool ) (string , error ) {
257
+ func (ic * ContainerEngine ) installQuadlet (_ context.Context , path , destName , installDir , assetFile string , isQuadletFile , force bool ) (string , error ) {
258
258
// First, validate that the source path exists and is a file
259
259
stat , err := os .Stat (path )
260
260
if err != nil {
@@ -274,9 +274,15 @@ func (ic *ContainerEngine) installQuadlet(_ context.Context, path, destName, ins
274
274
return "" , fmt .Errorf ("%q is not a supported Quadlet file type" , filepath .Ext (finalPath ))
275
275
}
276
276
277
- file , err := os .OpenFile (finalPath , os .O_CREATE | os .O_EXCL | os .O_WRONLY , 0644 )
277
+ var osFlags = os .O_CREATE | os .O_WRONLY
278
+
279
+ if ! force {
280
+ osFlags |= os .O_EXCL
281
+ }
282
+
283
+ file , err := os .OpenFile (finalPath , osFlags , 0644 )
278
284
if err != nil {
279
- if errors .Is (err , fs .ErrExist ) {
285
+ if errors .Is (err , fs .ErrExist ) && ! force {
280
286
return "" , fmt .Errorf ("a Quadlet with name %s already exists, refusing to overwrite" , filepath .Base (finalPath ))
281
287
}
282
288
return "" , fmt .Errorf ("unable to open file %s: %w" , filepath .Base (finalPath ), err )
0 commit comments