NewFsSrcDstFiles creates a new src and dst fs from the arguments If src is a file then srcFileName and dstFileName will be non-empty
(args []string)
| 178 | // NewFsSrcDstFiles creates a new src and dst fs from the arguments |
| 179 | // If src is a file then srcFileName and dstFileName will be non-empty |
| 180 | func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs, dstFileName string) { |
| 181 | ctx := context.Background() |
| 182 | fsrc, srcFileName = newFsFileAddFilter(args[0]) |
| 183 | // If copying a file... |
| 184 | dstRemote := args[1] |
| 185 | // If file exists then srcFileName != "", however if the file |
| 186 | // doesn't exist then we assume it is a directory... |
| 187 | if srcFileName != "" { |
| 188 | var err error |
| 189 | dstRemote, dstFileName, err = fspath.Split(dstRemote) |
| 190 | if err != nil { |
| 191 | fs.Fatalf(nil, "Parsing %q failed: %v", args[1], err) |
| 192 | } |
| 193 | if dstRemote == "" { |
| 194 | dstRemote = "." |
| 195 | } |
| 196 | if dstFileName == "" { |
| 197 | fs.Fatalf(nil, "%q is a directory", args[1]) |
| 198 | } |
| 199 | } |
| 200 | fdst, err := cache.Get(ctx, dstRemote) |
| 201 | switch err { |
| 202 | case fs.ErrorIsFile: |
| 203 | _ = fs.CountError(ctx, err) |
| 204 | fs.Fatalf(nil, "Source doesn't exist or is a directory and destination is a file") |
| 205 | case nil: |
| 206 | default: |
| 207 | _ = fs.CountError(ctx, err) |
| 208 | fs.Fatalf(nil, "Failed to create file system for destination %q: %v", dstRemote, err) |
| 209 | } |
| 210 | cache.Pin(fdst) // pin indefinitely since it was on the CLI |
| 211 | return |
| 212 | } |
| 213 | |
| 214 | // NewFsDstFile creates a new dst fs with a destination file name from the arguments |
| 215 | func NewFsDstFile(args []string) (fdst fs.Fs, dstFileName string) { |
no test coverage detected
searching dependent graphs…