databricks-cli/internal
Pieter Noordhuis 16bb224108
Add directory tracking to sync (#425)
## Changes

This change replaces usage of the `repofiles` package with the `filer`
package to consolidate WSFS code paths.

The `repofiles` package implemented the following behavior. If a file at
`foo/bar.txt` was created and removed, the directory `foo` was kept
around because we do not perform directory tracking. If subsequently, a
file at `foo` was created, it resulted in an `fs.ErrExist` because it is
impossible to overwrite a directory. It would then perform a recursive
delete of the path if this happened and retry the file write.

To make this use case work without resorting to a recursive delete on
conflict, we need to implement directory tracking as part of sync. The
approach in this commit is as follows:

1. Maintain set of directories needed for current set of files. Compare
to previous set of files. This results in mkdir of added directories and
rmdir of removed directories.
2. Creation of new directories should happen prior to writing files.
Otherwise, many file writes may race to create the same parent
directories, resulting in additional API calls. Removal of existing
directories should happen after removing files.
3. Making new directories can be deduped across common prefixes where
only the longest prefix is created recursively.
4. Removing existing directories must happen sequentially, starting with
the longest prefix.
5. Removal of directories is a best effort. It fails only if the
directory is not empty, and if this happens we know something placed a
file or directory manually, outside of sync.

## Tests

* Existing integration tests pass (modified where it used to assert
directories weren't cleaned up)
* New integration test to confirm the inability to remove a directory
doesn't fail the sync run
2023-06-12 11:44:00 +00:00
..
build Rename bricks -> databricks (#389) 2023-05-16 18:35:39 +02:00
api_test.go Rename bricks -> databricks (#389) 2023-05-16 18:35:39 +02:00
clusters_test.go Do not generate prompts for certain commands (#438) 2023-06-05 19:38:45 +02:00
filer_test.go Add workspace export-dir command (#449) 2023-06-08 18:15:12 +02:00
fs_cat_test.go Add fs cat command for dbfs files (#430) 2023-06-06 01:16:23 +02:00
fs_ls_test.go Add fs ls command for dbfs (#429) 2023-06-05 17:41:30 +02:00
helpers.go Speed up sync integration tests (#428) 2023-06-02 14:02:18 +00:00
locker_test.go Fix locker integration test (#417) 2023-06-01 09:38:03 +02:00
rm_test.go Add fs rm command for dbfs (#433) 2023-06-05 23:21:47 +00:00
secrets_test.go Do not prompt for List methods (#411) 2023-05-26 16:02:53 +02:00
sync_test.go Add directory tracking to sync (#425) 2023-06-12 11:44:00 +00:00
version_test.go Use cmdio in version command for `--output` flag (#419) 2023-06-01 12:03:22 +02:00
workspace_test.go Add workspace export-dir command (#449) 2023-06-08 18:15:12 +02:00