Move moves the file to the specified location
(ctx context.Context, src fs.Object, destinationPath string)
| 276 | |
| 277 | // Move moves the file to the specified location |
| 278 | func (f *Fs) Move(ctx context.Context, src fs.Object, destinationPath string) (fs.Object, error) { |
| 279 | |
| 280 | if strings.HasPrefix(destinationPath, "/") || strings.Contains(destinationPath, ":\\") { |
| 281 | dir := path.Dir(destinationPath) |
| 282 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 283 | return nil, fmt.Errorf("failed to create destination directory: %w", err) |
| 284 | } |
| 285 | |
| 286 | reader, err := src.Open(ctx) |
| 287 | if err != nil { |
| 288 | return nil, fmt.Errorf("failed to open source file: %w", err) |
| 289 | } |
| 290 | defer func() { |
| 291 | if err := reader.Close(); err != nil { |
| 292 | fs.Logf(nil, "Failed to close file body: %v", err) |
| 293 | } |
| 294 | }() |
| 295 | |
| 296 | dest, err := os.Create(destinationPath) |
| 297 | if err != nil { |
| 298 | return nil, fmt.Errorf("failed to create destination file: %w", err) |
| 299 | } |
| 300 | defer func() { |
| 301 | if err := dest.Close(); err != nil { |
| 302 | fs.Logf(nil, "Failed to close file body: %v", err) |
| 303 | } |
| 304 | }() |
| 305 | |
| 306 | if _, err := io.Copy(dest, reader); err != nil { |
| 307 | return nil, fmt.Errorf("failed to copy file content: %w", err) |
| 308 | } |
| 309 | |
| 310 | if err := src.Remove(ctx); err != nil { |
| 311 | return nil, fmt.Errorf("failed to remove source file: %w", err) |
| 312 | } |
| 313 | |
| 314 | return nil, nil |
| 315 | } |
| 316 | |
| 317 | reader, err := src.Open(ctx) |
| 318 | if err != nil { |
| 319 | return nil, fmt.Errorf("failed to open source object: %w", err) |
| 320 | } |
| 321 | defer func() { |
| 322 | if err := reader.Close(); err != nil { |
| 323 | fs.Logf(nil, "Failed to close file body: %v", err) |
| 324 | } |
| 325 | }() |
| 326 | |
| 327 | err = f.uploadFile(ctx, reader, destinationPath) |
| 328 | if err != nil { |
| 329 | return nil, fmt.Errorf("failed to upload file to destination: %w", err) |
| 330 | } |
| 331 | |
| 332 | if err := src.Remove(ctx); err != nil { |
| 333 | return nil, fmt.Errorf("failed to delete source file: %w", err) |
| 334 | } |
| 335 |
nothing calls this directly
no test coverage detected