Bug 225289 - Restore pre-r276879 behavior for FileSystem::deleteFile() and FileSystem::deleteEmptyDirectory()
Summary: Restore pre-r276879 behavior for FileSystem::deleteFile() and FileSystem::del...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on: 225522
Blocks:
  Show dependency treegraph
 
Reported: 2021-05-02 19:22 PDT by Chris Dumez
Modified: 2021-05-10 18:30 PDT (History)
12 users (show)

See Also:


Attachments
Patch (14.04 KB, patch)
2021-05-02 19:32 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (14.09 KB, patch)
2021-05-03 08:03 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2021-05-02 19:22:33 PDT
Restore pre-r276879 behavior for FileSystem::deleteFile() and FileSystem::deleteEmptyDirectory().
Comment 1 Chris Dumez 2021-05-02 19:32:06 PDT
Created attachment 427537 [details]
Patch
Comment 2 Chris Dumez 2021-05-03 08:03:46 PDT
Created attachment 427558 [details]
Patch
Comment 3 Darin Adler 2021-05-03 10:02:25 PDT
Comment on attachment 427558 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=427558&action=review

> Source/WTF/wtf/FileSystem.cpp:493
>  bool deleteFile(const String& path)

Maybe later we want to add a new call that matches more directly what std::filesystem::remove does, and remove these? I don’t think all callers *need* to do the "only do it if it’s a file/directory" version; it’s just that before we were starting by mirroring that feature of the POSIX API where unlink is for files only and rmdir is for directories only. Now we are in a funny place where we are more work for a semantic callers might not need.

> Source/WTF/wtf/FileSystem.cpp:506
>  bool deleteEmptyDirectory(const String& path)

Given the complexity of all the ".DS_Store" stuff on Mac, maybe we should consider eventually getting rid of deleteEmptyDirectory to instead use a function that can delete even non-empty ones. I suppose it’s a safety measure to prevent deleting a lot of files that we use deleteEmptyDirectory.
Comment 4 Chris Dumez 2021-05-03 10:07:01 PDT
(In reply to Darin Adler from comment #3)
> Comment on attachment 427558 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=427558&action=review
> 
> > Source/WTF/wtf/FileSystem.cpp:493
> >  bool deleteFile(const String& path)
> 
> Maybe later we want to add a new call that matches more directly what
> std::filesystem::remove does, and remove these? I don’t think all callers
> *need* to do the "only do it if it’s a file/directory" version; it’s just
> that before we were starting by mirroring that feature of the POSIX API
> where unlink is for files only and rmdir is for directories only. Now we are
> in a funny place where we are more work for a semantic callers might not
> need.

Yes, I agree. I will look into this. For now, I figure the safest choice is to maintain pre-existing behavior until I can check all call sites.

> 
> > Source/WTF/wtf/FileSystem.cpp:506
> >  bool deleteEmptyDirectory(const String& path)
> 
> Given the complexity of all the ".DS_Store" stuff on Mac, maybe we should
> consider eventually getting rid of deleteEmptyDirectory to instead use a
> function that can delete even non-empty ones. I suppose it’s a safety
> measure to prevent deleting a lot of files that we use deleteEmptyDirectory.

I think we view deleteEmptyDirectory() as a way to avoid deleting non-webkit files in webkit folders. For example, I have a database IndexedDB.db in a IndexedDB/ folder and I want to remove the database. We usually call removeFile(IndexedDB.db) to remove our database, then deleteEmptyDirectory("IndexedDB/") to remove the folder but only if there is nothing else in it. I guess one worry is that the user might put a file in that WebKit directory and we wouldn't want to delete it. It seems unlikely to happen in practice but we try to stay on the safe side.
Comment 5 EWS 2021-05-03 10:23:35 PDT
Committed r276906 (237251@main): <https://commits.webkit.org/237251@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 427558 [details].
Comment 6 Radar WebKit Bug Importer 2021-05-03 10:24:18 PDT
<rdar://problem/77460938>