Skip to content

Commit 4e0e1dc

Browse files
authored
Merge pull request #231 from achilleas-k/multiaddfix
Fix filename metadata write
2 parents b06276c + c236a53 commit 4e0e1dc

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

git/annex.go

+14-16
Original file line numberDiff line numberDiff line change
@@ -778,10 +778,7 @@ func annexAddCommon(filepaths []string, update bool, addchan chan<- RepoFileStat
778778
status.State = "Locking"
779779
}
780780

781-
// Start the metadata setter routine
782-
mdchan := make(chan string)
783-
defer close(mdchan)
784-
go setAnnexMetadataName(mdchan)
781+
var filenames []string
785782
for rerr = nil; rerr == nil; outline, rerr = cmd.OutReader.ReadBytes('\n') {
786783
if len(outline) == 0 {
787784
// Empty line output. Ignore
@@ -799,8 +796,7 @@ func annexAddCommon(filepaths []string, update bool, addchan chan<- RepoFileStat
799796
if addresult.Success {
800797
log.Write("%s added to annex", addresult.File)
801798
status.Err = nil
802-
// Write filename metadata key
803-
mdchan <- status.FileName
799+
filenames = append(filenames, status.FileName)
804800
} else {
805801
log.Write("Error adding %s", addresult.File)
806802
status.Err = fmt.Errorf("failed")
@@ -816,22 +812,24 @@ func annexAddCommon(filepaths []string, update bool, addchan chan<- RepoFileStat
816812
log.Write("Error during AnnexAdd")
817813
logstd(nil, stderr)
818814
}
815+
// Add metadata
816+
for _, fname := range filenames {
817+
setAnnexMetadataName(fname)
818+
}
819819
return
820820
}
821821

822822
// setAnnexMetadataName starts a routine and waits for input on the provided channel.
823823
// For each path specified, the name of the file is added to the metadata of the annexed file.
824824
// 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)
835833
}
836834
return
837835
}

tests

0 commit comments

Comments
 (0)