| 183 | } |
| 184 | |
| 185 | func determineTransferDirection(sources []PathInfo, dest PathInfo) (string, string, error) { |
| 186 | remoteCount := 0 |
| 187 | var remoteInstanceID string |
| 188 | |
| 189 | for _, src := range sources { |
| 190 | if src.IsRemote { |
| 191 | remoteCount++ |
| 192 | if remoteInstanceID == "" { |
| 193 | remoteInstanceID = src.InstanceID |
| 194 | } else if remoteInstanceID != src.InstanceID { |
| 195 | return "", "", usageErr("cannot transfer between multiple instances") |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | if dest.IsRemote { |
| 201 | if remoteCount > 0 { |
| 202 | return "", "", usageErr("cannot transfer from remote to remote") |
| 203 | } |
| 204 | return "upload", dest.InstanceID, nil |
| 205 | } |
| 206 | |
| 207 | if remoteCount == 0 { |
| 208 | return "", "", usageErr("no remote path specified (use instance_id:/path)") |
| 209 | } |
| 210 | |
| 211 | return "download", remoteInstanceID, nil |
| 212 | } |