purgeCheck removes the directory dir, if check is set then it refuses to do so if it has anything in
(ctx context.Context, dir string, check bool)
| 674 | // purgeCheck removes the directory dir, if check is set then it |
| 675 | // refuses to do so if it has anything in |
| 676 | func (f *Fs) purgeCheck(ctx context.Context, dir string, check bool) error { |
| 677 | f.mkdirMu.Lock() |
| 678 | defer f.mkdirMu.Unlock() |
| 679 | |
| 680 | rootNode, err := f.findRoot(ctx, false) |
| 681 | if err != nil { |
| 682 | return err |
| 683 | } |
| 684 | dirNode, err := f.findDir(rootNode, dir) |
| 685 | if err != nil { |
| 686 | return err |
| 687 | } |
| 688 | |
| 689 | if check { |
| 690 | children, err := f.srv.FS.GetChildren(dirNode) |
| 691 | if err != nil { |
| 692 | return fmt.Errorf("purgeCheck GetChildren failed: %w", err) |
| 693 | } |
| 694 | if len(children) > 0 { |
| 695 | return fs.ErrorDirectoryNotEmpty |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | waitEvent := f.srv.WaitEventsStart() |
| 700 | |
| 701 | err = f.deleteNode(ctx, dirNode) |
| 702 | if err != nil { |
| 703 | return fmt.Errorf("delete directory node failed: %w", err) |
| 704 | } |
| 705 | |
| 706 | // Remove the root node if we just deleted it |
| 707 | if dirNode == rootNode { |
| 708 | f.clearRoot() |
| 709 | } |
| 710 | |
| 711 | f.srv.WaitEvents(waitEvent, eventWaitTime) |
| 712 | return nil |
| 713 | } |
| 714 | |
| 715 | // Rmdir deletes the root folder |
| 716 | // |