Skip to content

Commit 8fad084

Browse files
committed
collection.MoveFilesIntoAnotherCollection: allow insta-creating new collection
1 parent ba13553 commit 8fad084

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

pkg/stoserver/commandhandlerscollectionmutations.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,30 @@ func (c *cHandlers) CollectionMoveFilesIntoAnotherCollection(cmd *stoservertypes
2525
return err
2626
}
2727

28-
if cmd.Source == cmd.Destination {
29-
return errors.New("source and destination cannot be same")
30-
}
31-
3228
return c.db.Update(func(tx *bbolt.Tx) error {
3329
collSrc, err := stodb.Read(tx).Collection(cmd.Source)
3430
if err != nil {
3531
return err
3632
}
3733

38-
collDst, err := stodb.Read(tx).Collection(cmd.Destination)
34+
collDst, err := func() (*stotypes.Collection, error) {
35+
if nameNewCollection := cmd.NameNewCollection; nameNewCollection != "" {
36+
if cmd.Destination != "" {
37+
return nil, errors.New("in the case of making a new collection the destination must be empty")
38+
}
39+
return createCollection(nameNewCollection, collSrc.Directory, c.conf.KeyStore, tx)
40+
} else {
41+
if cmd.Destination == "" || cmd.Source == cmd.Destination {
42+
return nil, errors.New("source and destination cannot be same")
43+
}
44+
45+
return stodb.Read(tx).Collection(cmd.Destination)
46+
}
47+
}()
3948
if err != nil {
4049
return err
4150
}
4251

43-
if cmd.Source == cmd.Destination {
44-
return errors.New("source and destination cannot be same")
45-
}
46-
4752
sourceState, err := stateresolver.ComputeStateAtHead(*collSrc)
4853
if err != nil {
4954
return err

pkg/stoserver/stoservertypes/commands.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@
481481
"fields": [
482482
{ "key": "Source", "hideIfDefaultValue": true },
483483
{ "key": "Files", "type": "StringList", "hideIfDefaultValue": true },
484-
{ "key": "Destination", "title": "Destination collection", "placeholder": "(search)", "type": "custom/string" }
484+
{ "key": "Destination", "title": "Destination collection", "placeholder": "(search)", "type": "custom/string", "optional": true },
485+
{ "key": "NameNewCollection", "title": "Name of new collection", "placeholder": "(create new collection)", "optional": true, "help": "If defined, new collection is created (as sibling of source collection). In this case leave destination unset." }
485486
]
486487
},
487488
{

0 commit comments

Comments
 (0)