Skip to content

Commit f2220bd

Browse files
ivaninkvsimulot
authored andcommitted
Added overwrite flag for upload sub-command
1 parent 20fb688 commit f2220bd

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

app/cmd/upload/run.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,26 @@ func (upCmd *UpCmd) handleAsset(ctx context.Context, a *assets.Asset) error {
335335
return err
336336
}
337337

338+
if upCmd.Overwrite {
339+
if advice.ServerAsset != nil {
340+
// Remember existing asset's albums, if any
341+
a.Albums = append(a.Albums, advice.ServerAsset.Albums...)
342+
343+
// Upload the superior asset
344+
serverStatus, err := upCmd.replaceAsset(ctx, advice.ServerAsset.ID, a, advice.ServerAsset)
345+
if err != nil {
346+
return err
347+
}
348+
if serverStatus != immich.StatusDuplicate {
349+
upCmd.manageAssetAlbums(ctx, a.File, a.ID, a.Albums)
350+
upCmd.manageAssetTags(ctx, a)
351+
}
352+
return nil
353+
}
354+
// If no existing asset, treat as a new upload
355+
advice.Advice = NotOnServer
356+
}
357+
338358
switch advice.Advice {
339359
case NotOnServer: // Upload and manage albums
340360
serverStatus, err := upCmd.uploadAsset(ctx, a)

app/cmd/upload/upload.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ type UploadOptions struct {
3939
// TODO place this option at the top
4040
NoUI bool // Disable UI
4141

42+
// Add Overwrite flag to UploadOptions
43+
Overwrite bool // Always overwrite files on the server with local versions
44+
4245
Filters []filters.Filter
4346
}
4447

@@ -52,6 +55,7 @@ func NewUploadCommand(ctx context.Context, a *app.Application) *cobra.Command {
5255
app.AddClientFlags(ctx, cmd, a, false)
5356
cmd.TraverseChildren = true
5457
cmd.PersistentFlags().BoolVar(&options.NoUI, "no-ui", false, "Disable the user interface")
58+
cmd.PersistentFlags().BoolVar(&options.Overwrite, "overwrite", false, "Always overwrite files on the server with local versions")
5559
cmd.PersistentPreRunE = app.ChainRunEFunctions(cmd.PersistentPreRunE, options.Open, ctx, cmd, a)
5660

5761
cmd.AddCommand(NewFromFolderCommand(ctx, cmd, a, options))

readme.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@ Increase the **--client-timeout** when you have some timeout issues with the ser
265265
Thanks to the **--session-tag** option, it's easy to identify all photos uploaded during a session, and remove them if needed.
266266
This tag is formatted as `{immich-go}/YYYY-MM-DD HH-MM-SS`. The tag can be deleted without removing the photos.
267267

268+
## **--overwrite**
269+
The `--overwrite` flag ensures that files on the server are always replaced with their local versions during the upload process. If a file does not exist on the server, it will be uploaded as a new file. This option is useful for ensuring that the server always has the latest version of your files.
270+
271+
Example:
272+
```bash
273+
immich-go upload from-folder --server=http://your-ip:2283 --api-key=your-api-key --overwrite /path/to/your/photos
274+
```
268275

269276
# The **archive** command:
270277

@@ -680,4 +687,3 @@ A big thank you to the project contributors:
680687
- [mrwulf](https://github.com/mrwulf) Partner sharing album
681688
- [erkexzcx](https://github.com/erkexzcx) Date determination based on file path and file name
682689
- [benjamonnguyen](https://github.com/benjamonnguyen) Tag API calls
683-

0 commit comments

Comments
 (0)