To retain more control over the synchronization process, you can utilize two additional options available for all synchronization functions: backup and force.
Backup Option: Setting
backup = TRUE will create a backup (copy) of the right
directory before performing the synchronization. This backup is stored
in the location specified by backup_dir. If
backup_dir is not provided, the backup will be saved in a
temporary directory (tempdir). This ensures that you can
revert to the previous state if needed
Force Option: By default,
force = TRUE, make all functions proceed directly with the
synchronization without user’s confirmation. However, to avoid
unintended changes to your directories, you can set
force = FALSE. This way the function will first display a
preview of the proposed actions, including which files will be copied
and which will be deleted. You will be prompted to confirm whether you
wish to proceed with these actions. Synchronization will only continue
if you agree; otherwise, it will be aborted, and no changes will be made
to the directories.
For example, suppose you are performing a full asymmetric synchronization of your, say, left and right directories. This type of synchronization entails that certain files will be copied over to the right directory, as well as that certain files will be deleted from it.
To maintain greater control over the process, you can allow the function to perform the synchronization while simultaneously storing a copy of the original directory before any changes occur. This way, you can revert to the original if needed.
# generate toy directories
e <- toy_dirs()
#> ■■■■■■■■■ 27% | ETA: 9s
#> ■■■■■■■■■■■■■■■■■■■ 60% | ETA: 6s
.syncdrenv.1 <- syncdr:::copy_temp_environment()
# Get left and right directories' paths
left <- .syncdrenv.1$left
right <- .syncdrenv.1$right
sync_status <- compare_directories(left, right)
# call sync function
full_asym_sync_to_right(sync_status = sync_status,
backup = TRUE)
#> ✔ synchronizedAnother option is to visualize a preliminary check, before the synchronization takes place. This can be done taking advantage of the force option. Note that prompt for user confirmation will work when you run the function interactively in your R session. However, this interactive prompt will not be functional within this article.
full_asym_sync_to_right(sync_status = sync_status,
force = FALSE)
#> These files will be DELETED in right
#>
#> |Files |Action |
#> |:-------------------|:-------------|
#> |/C/C1_duplicate.Rds |To be deleted |
#> |/D/D3.Rds |To be deleted |
#> |/E/E1.Rds |To be deleted |
#> |/E/E2.Rds |To be deleted |
#> |/E/E3.Rds |To be deleted |
#> These files will be COPIED (overwriting if present) to right
#>
#>
#> |Files |Action |
#> |:---------|:------------|
#> |/D/D1.Rds |To be copied |
#> |/D/D2.Rds |To be copied |
#> |/A/A1.Rds |To be copied |
#> |/A/A2.Rds |To be copied |
#> |/A/A3.Rds |To be copied |
#> |/B/B3.Rds |To be copied |
#> Do you want to proceed? Type your answer (Yes/no/cancel)
#> ✔ synchronized
#You will need to type `no` or 'cancel' to stop the synchronization