This repository was archived by the owner on Feb 7, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ func (s *Shell) AddLink(target string) (string, error) {
97
97
}
98
98
99
99
// AddDir adds a directory recursively with all of the files under it
100
- func (s * Shell ) AddDir (dir string ) (string , error ) {
100
+ func (s * Shell ) AddDir (dir string , options ... AddOpts ) (string , error ) {
101
101
stat , err := os .Lstat (dir )
102
102
if err != nil {
103
103
return "" , err
@@ -110,14 +110,18 @@ func (s *Shell) AddDir(dir string) (string, error) {
110
110
slf := files .NewSliceDirectory ([]files.DirEntry {files .FileEntry (filepath .Base (dir ), sf )})
111
111
reader := files .NewMultiFileReader (slf , true )
112
112
113
- resp , err := s .Request ("add" ).
114
- Option ("recursive" , true ).
115
- Body (reader ).
116
- Send (context .Background ())
113
+ rb := s .Request ("add" ).Option ("recursive" , true )
114
+ for _ , option := range options {
115
+ option (rb )
116
+ }
117
+
118
+ // Here we cannot use .Exec because "add" streams responses back for each file
119
+ // within the directory, and we only care about the last one, which is the directory
120
+ // itself.
121
+ resp , err := rb .Body (reader ).Send (context .Background ())
117
122
if err != nil {
118
123
return "" , err
119
124
}
120
-
121
125
defer resp .Close ()
122
126
123
127
if resp .Error != nil {
Original file line number Diff line number Diff line change @@ -125,6 +125,15 @@ func TestAddDir(t *testing.T) {
125
125
is .Equal (cid , "QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv" )
126
126
}
127
127
128
+ func TestAddDirWithCidV1 (t * testing.T ) {
129
+ is := is .New (t )
130
+ s := NewShell (shellUrl )
131
+
132
+ cid , err := s .AddDir ("./testdata" , CidVersion (1 ))
133
+ is .Nil (err )
134
+ is .Equal (cid , "bafybeibgegl5yqme2jehvvneapbq7he5ahi3tmk4cpmlagrggeji6hzayq" )
135
+ }
136
+
128
137
func TestAddDirOffline (t * testing.T ) {
129
138
is := is .New (t )
130
139
s := NewShell ("0.0.0.0:1234" ) // connect to an invalid address
You can’t perform that action at this time.
0 commit comments