Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Automatically remove old persistent cache dir - #18244

Merged
liyuqian merged 2 commits into
flutter-team-archive:masterfrom
liyuqian:free_persistent_cache
May 15, 2020
Merged

liyuqian merged 2 commits into
flutter-team-archive:masterfrom
liyuqian:free_persistent_cache

Conversation

@liyuqian

@liyuqian liyuqian commented May 8, 2020 •

Copy link
Copy Markdown
Contributor

Fixes flutter/flutter#53445

I was just notified today that there's a deadline of fixing this before 5/14/2020.

@liyuqian
liyuqian requested a review from chinmaygarde May 8, 2020 23:00
@auto-assign
auto-assign Bot requested a review from cbracken May 8, 2020 23:00
@liyuqian
liyuqian force-pushed the free_persistent_cache branch 2 times, most recently from a99de4d to 533b5f3 Compare May 8, 2020 23:08
@liyuqian
liyuqian requested review from gw280 and iskakaushik May 8, 2020 23:10
Comment thread fml/file.cc Outdated

} // namespace fml

void fml::RemoveFilesInDirectory(const fml::UniqueFD& directory) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this inside the namespace fml block

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread shell/common/persistent_cache.cc Outdated
auto dir = fml::OpenDirectory(directory, filename.c_str(), false,
fml::FilePermission::kReadWrite);
if (dir.is_valid()) {
fml::RemoveFilesInDirectory(dir);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be simpler to have the directory tree delete function take a parent UniqueFD and the name of the directory to delete (similar to fml::UnlinkDirectory, but recursive).

With that change the delete function can unlink the directory itself after all the contents have been removed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with RemoveDirectoryRecursively added. The old RemoveFilesInDirectory is still preserved for unit tests (e.g., https://github.com/flutter/engine/pull/18244/files#diff-b3bfc82230a960f6d96fe512bacd4d7cR235)

TEST_F(ShellTest, CanRemoveOldPersistentCache) {
fml::ScopedTemporaryDirectory base_dir;

fml::CreateDirectory(base_dir.fd(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert that you actually got the FD here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread fml/file.cc Outdated

} // namespace fml

void fml::RemoveFilesInDirectory(const fml::UniqueFD& directory) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this in the FML namespace block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread fml/file.h Outdated

/// Helper method to recursively remove files and subdirectories inside the
/// directory. The directory itself will not be removed.
void RemoveFilesInDirectory(const fml::UniqueFD& directory);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some error handling would be good here. Return a bool to notify that the files were actually deleted maybe. Right now, failures are silent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@iskakaushik iskakaushik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@liyuqian
liyuqian force-pushed the free_persistent_cache branch from 551566a to 8382c33 Compare May 13, 2020 21:40
@liyuqian

Copy link
Copy Markdown
Contributor Author

@liyuqian
liyuqian merged commit a4fb3de into flutter-team-archive:master May 15, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 16, 2020
@liyuqian
liyuqian deleted the free_persistent_cache branch May 19, 2020 21:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Development

Successfully merging this pull request may close these issues.

Remove old persistent cache

5 participants