Skip to content

Keep a file listed in a project folder when another program saves over it - #407

Open
DerpyNewb wants to merge 1 commit into
donkeyProgramming:masterfrom
DerpyNewb:pr/project-folder-save-by-rename
Open

DerpyNewb wants to merge 1 commit into
donkeyProgramming:masterfrom
DerpyNewb:pr/project-folder-save-by-rename

Conversation

@DerpyNewb

Copy link
Copy Markdown
Contributor

hey, this one matters more now that project folders are the default way to work. open a texture from a project folder in Photoshop (or most image editors), save it, and the file disappears from the pack explorer, even though it's still on disk

those programs save by writing a temp file and renaming it over the original, so the folder watcher sees the name deleted and created again inside one 300 ms batch. ProcessPendingEvents applied every delete after every create, and a create of a name that was still listed got skipped, so what was left was the delete

now the batch is replayed in order against the listed names and only the net change is applied. a file that got saved over keeps its entry and gets the new file as its source, and a temp file that comes and goes inside the same batch is never added

files

  • Shared.Core/PackFiles/Models/Containers/SystemFolderContainer.cs: the batch handling in ProcessPendingEvents and its two private helpers, no API change
  • Shared.CoreTest/PackFiles/Models/Containers/SystemFolderContainerTests_RealWatcher.cs: new

testing

  • the new test uses Windows' real watcher (FileSystemWatcherWrapper), not the mock, on four ways of saving over a file: delete then rewrite, temp + delete + rename, rename away + rename in + delete the backup, and File.Replace. against the current code all four drop the file. with this change all four pass, 10 runs in a row here
  • it waits for a marker file to get listed instead of sleeping a fixed time, so a slow CI box should be fine (it gives up after 5 s per case)
  • Shared.CoreTest: 426 passed, 0 failed, 6 skipped (the existing Assert.Ignores in the pack container tests)
  • built AssetEditor.csproj the way pr-test.yml does, 0 errors

…r it

Photoshop and most image editors save by writing a temp file and renaming it into the
original's place, so the watcher sees the name deleted and created again inside one 300 ms
batch. Deletes were applied after every create, and a create of a name still listed was
skipped, so the file dropped off the list. The batch is now replayed in order and only the net
change is applied; a saved-over entry keeps its place and gets the new file as its source.

The test uses Windows' real watcher on four ways of saving over a file (rewrite, temp + delete
+ rename, rename away + rename in, File.Replace). All four failed before.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant