operation should be "make" or "remove"
(ctx context.Context, dst fs.Fs, candidates bilib.Names, dirsList *fileList, results *[]Results, operation string)
| 302 | |
| 303 | // operation should be "make" or "remove" |
| 304 | func (b *bisyncRun) syncEmptyDirs(ctx context.Context, dst fs.Fs, candidates bilib.Names, dirsList *fileList, results *[]Results, operation string) { |
| 305 | if b.InGracefulShutdown { |
| 306 | return |
| 307 | } |
| 308 | fs.Debugf(nil, "syncing empty dirs") |
| 309 | if b.opt.CreateEmptySrcDirs && (!b.opt.Resync || operation == "make") { |
| 310 | |
| 311 | candidatesList := candidates.ToList() |
| 312 | if operation == "remove" { |
| 313 | // reverse the sort order to ensure we remove subdirs before parent dirs |
| 314 | sort.Sort(sort.Reverse(sort.StringSlice(candidatesList))) |
| 315 | } |
| 316 | |
| 317 | for _, s := range candidatesList { |
| 318 | var direrr error |
| 319 | if dirsList.has(s) { // make sure it's a dir, not a file |
| 320 | r := Results{} |
| 321 | r.Name = s |
| 322 | r.Size = -1 |
| 323 | r.Modtime = dirsList.getTime(s).In(time.UTC) |
| 324 | r.Flags = "d" |
| 325 | r.Err = nil |
| 326 | r.Origin = "syncEmptyDirs" |
| 327 | r.Winner = operations.Winner{ // note: Obj not set |
| 328 | Side: "src", |
| 329 | Err: nil, |
| 330 | } |
| 331 | |
| 332 | rSrc := r |
| 333 | rDst := r |
| 334 | rSrc.IsSrc = true |
| 335 | rSrc.IsDst = false |
| 336 | rDst.IsSrc = false |
| 337 | rDst.IsDst = true |
| 338 | rSrc.IsWinner = true |
| 339 | rDst.IsWinner = false |
| 340 | |
| 341 | if operation == "remove" { |
| 342 | // directories made empty by the sync will have already been deleted during the sync |
| 343 | // this just catches the already-empty ones (excluded from sync by --files-from filter) |
| 344 | direrr = operations.TryRmdir(ctx, dst, s) |
| 345 | rSrc.Sigil = operations.MissingOnSrc |
| 346 | rDst.Sigil = operations.MissingOnSrc |
| 347 | rSrc.Dst = s |
| 348 | rDst.Dst = s |
| 349 | rSrc.Winner.Side = "none" |
| 350 | rDst.Winner.Side = "none" |
| 351 | } else if operation == "make" { |
| 352 | direrr = operations.Mkdir(ctx, dst, s) |
| 353 | rSrc.Sigil = operations.MissingOnDst |
| 354 | rDst.Sigil = operations.MissingOnDst |
| 355 | rSrc.Src = s |
| 356 | rDst.Src = s |
| 357 | } else { |
| 358 | direrr = fmt.Errorf("invalid operation. Expected 'make' or 'remove', received '%q'", operation) |
| 359 | } |
| 360 | |
| 361 | if direrr != nil { |