@@ -778,10 +778,7 @@ func annexAddCommon(filepaths []string, update bool, addchan chan<- RepoFileStat
778
778
status .State = "Locking"
779
779
}
780
780
781
- // Start the metadata setter routine
782
- mdchan := make (chan string )
783
- defer close (mdchan )
784
- go setAnnexMetadataName (mdchan )
781
+ var filenames []string
785
782
for rerr = nil ; rerr == nil ; outline , rerr = cmd .OutReader .ReadBytes ('\n' ) {
786
783
if len (outline ) == 0 {
787
784
// Empty line output. Ignore
@@ -799,8 +796,7 @@ func annexAddCommon(filepaths []string, update bool, addchan chan<- RepoFileStat
799
796
if addresult .Success {
800
797
log .Write ("%s added to annex" , addresult .File )
801
798
status .Err = nil
802
- // Write filename metadata key
803
- mdchan <- status .FileName
799
+ filenames = append (filenames , status .FileName )
804
800
} else {
805
801
log .Write ("Error adding %s" , addresult .File )
806
802
status .Err = fmt .Errorf ("failed" )
@@ -816,22 +812,24 @@ func annexAddCommon(filepaths []string, update bool, addchan chan<- RepoFileStat
816
812
log .Write ("Error during AnnexAdd" )
817
813
logstd (nil , stderr )
818
814
}
815
+ // Add metadata
816
+ for _ , fname := range filenames {
817
+ setAnnexMetadataName (fname )
818
+ }
819
819
return
820
820
}
821
821
822
822
// setAnnexMetadataName starts a routine and waits for input on the provided channel.
823
823
// For each path specified, the name of the file is added to the metadata of the annexed file.
824
824
// The function exits when the channel is closed.
825
- func setAnnexMetadataName (pathchan <- chan string ) {
826
- for path := range pathchan {
827
- _ , fname := filepath .Split (path )
828
- cmd := AnnexCommand ("metadata" , fmt .Sprintf ("--set=ginfilename=%s" , fname ), path )
829
- stdout , stderr , err := cmd .OutputError ()
830
- if err != nil {
831
- logstd (stdout , stderr )
832
- } else {
833
- log .Write ("ginfilename metadata key set to %s" , fname )
834
- }
825
+ func setAnnexMetadataName (path string ) {
826
+ _ , fname := filepath .Split (path )
827
+ cmd := AnnexCommand ("metadata" , fmt .Sprintf ("--set=ginfilename=%s" , fname ), path )
828
+ stdout , stderr , err := cmd .OutputError ()
829
+ if err != nil {
830
+ logstd (stdout , stderr )
831
+ } else {
832
+ log .Write ("ginfilename metadata key set to %s" , fname )
835
833
}
836
834
return
837
835
}
0 commit comments