Rmdir removes the directory (container, bucket) if empty
(ctx context.Context, dir string)
| 1181 | |
| 1182 | // Rmdir removes the directory (container, bucket) if empty |
| 1183 | func (f *Fs) Rmdir(ctx context.Context, dir string) error { |
| 1184 | fs.Debugf(f, "rmdir '%s'", dir) |
| 1185 | |
| 1186 | if f.opt.TempWritePath != "" { |
| 1187 | // pause background uploads |
| 1188 | f.backgroundRunner.pause() |
| 1189 | defer f.backgroundRunner.play() |
| 1190 | |
| 1191 | // we check if the source exists on the remote and make the same move on it too if it does |
| 1192 | // otherwise, we skip this step |
| 1193 | _, err := f.UnWrap().List(ctx, dir) |
| 1194 | if err == nil { |
| 1195 | err := f.Fs.Rmdir(ctx, dir) |
| 1196 | if err != nil { |
| 1197 | return err |
| 1198 | } |
| 1199 | fs.Debugf(dir, "rmdir: removed dir in source fs") |
| 1200 | } |
| 1201 | |
| 1202 | var queuedEntries []*Object |
| 1203 | err = walk.ListR(ctx, f.tempFs, dir, true, -1, walk.ListObjects, func(entries fs.DirEntries) error { |
| 1204 | for _, o := range entries { |
| 1205 | if oo, ok := o.(fs.Object); ok { |
| 1206 | co := ObjectFromOriginal(ctx, f, oo) |
| 1207 | queuedEntries = append(queuedEntries, co) |
| 1208 | } |
| 1209 | } |
| 1210 | return nil |
| 1211 | }) |
| 1212 | if err != nil { |
| 1213 | fs.Errorf(dir, "rmdir: error getting pending uploads: %v", err) |
| 1214 | } else { |
| 1215 | fs.Debugf(dir, "rmdir: read %v from temp fs", len(queuedEntries)) |
| 1216 | fs.Debugf(dir, "rmdir: temp fs entries: %v", queuedEntries) |
| 1217 | if len(queuedEntries) > 0 { |
| 1218 | fs.Errorf(dir, "rmdir: temporary dir not empty: %v", queuedEntries) |
| 1219 | return fs.ErrorDirectoryNotEmpty |
| 1220 | } |
| 1221 | } |
| 1222 | } else { |
| 1223 | err := f.Fs.Rmdir(ctx, dir) |
| 1224 | if err != nil { |
| 1225 | return err |
| 1226 | } |
| 1227 | fs.Debugf(dir, "rmdir: removed dir in source fs") |
| 1228 | } |
| 1229 | |
| 1230 | // remove dir data |
| 1231 | d := NewDirectory(f, dir) |
| 1232 | err := f.cache.RemoveDir(d.abs()) |
| 1233 | if err != nil { |
| 1234 | fs.Errorf(dir, "rmdir: remove error: %v", err) |
| 1235 | } else { |
| 1236 | fs.Debugf(d, "rmdir: removed from cache") |
| 1237 | } |
| 1238 | // expire parent |
| 1239 | parentCd := NewDirectory(f, cleanPath(path.Dir(dir))) |
| 1240 | err = f.cache.ExpireDir(parentCd) |
nothing calls this directly
no test coverage detected