[flutter_tools] join flutter specific with home cache#105343
[flutter_tools] join flutter specific with home cache#105343auto-submit[bot] merged 26 commits intoflutter:masterfrom
Conversation
There was a problem hiding this comment.
Logic for finding the default PUB_CACHE is here:
https://github.com/dart-lang/pub/blob/73ea9a98b5bef9cd2b1ca4d1eba8b6d20e1ad3d0/lib/src/system_cache.dart#L40-L60
There is occasionally some discussion around moving to a more XDG compliant location. But that's not happening right now. Feel free to file a PR against pub with a //NOTE: .... saying that when changing this we should also patch flutter_tools.
|
Isn't there also an opportunity to cleanup: flutter/bin/internal/shared.sh Lines 152 to 154 in be0c1bd (and similar thing in the |
There was a problem hiding this comment.
commented out code
There was a problem hiding this comment.
You can't hard code '/' as this will be wrong on Windows. You can copy the rest of this file, where _fileSystem.path.join(...) is called.
Also, will detecting the home directory work this way on Windows?
There was a problem hiding this comment.
| void joinCaches(FileSystem fileSystem, String targetPath, String extraPath) { | |
| void joinCaches({ | |
| required FileSystem fileSystem, | |
| required String destinationPath, | |
| required String sourcePath, | |
| ) { |
There was a problem hiding this comment.
readAsBytesSync -> writeAsBytesSync will pull the entire file into memory before writing it again; this will use a lot of resources and be slow; use https://api.dart.dev/stable/2.17.3/dart-io/File/renameSync.html (per that dartdoc, if the source and destination paths are on different filesystems, that may fail, so maybe copy + delete would be safer?)
There was a problem hiding this comment.
A FileSystemEntity doesn't have to be a file, I think instead you need to check if entity is File
There was a problem hiding this comment.
I think we can probably just recursively delete the entire local cache at the end.
There was a problem hiding this comment.
I didn't want to face the issue of running out of memory. But if we don't think that will happen a lot I can delete this line
There was a problem hiding this comment.
(doing many little deletes will be much slower than a single file system call)
There was a problem hiding this comment.
Isn't there also an opportunity to cleanup:
flutter/bin/internal/shared.sh
Lines 152 to 154 in be0c1bd
(and similar thing in the
.batvariant)
@jonasfj
As I mention in this comment we are not actually deleting the FLUTTER_ROOT/.pub-cache always, we are just doing that when FLUTTER_ROOT/.pub-cache and HOME/.pub-cache are available in the users environment so I don't think deleting the PUB-CACHE variable will be correct
There was a problem hiding this comment.
style nit: de-dent once and add a trailing comma to line 62
There was a problem hiding this comment.
You added the comma, but not the de-dent
There was a problem hiding this comment.
style nit: de-dent once and add a trailing comma to line 555
There was a problem hiding this comment.
Here, and lines 564, 567, 571-573, please de-dent once and add trailing commas where there aren't one already
There was a problem hiding this comment.
nit: can you update the parameter names for joinCaches to be globalCachePath and localCachePath. Also change the local variables here to match.
There was a problem hiding this comment.
style nit: this else if should be on the previous line, after the close curly brace
There was a problem hiding this comment.
@jonasfj I copy paste this comment from the dart-lang repo. Also can you double check on this logic for windows? Thanks.
There was a problem hiding this comment.
This is a surprising API to me. would it make sense to require the caller to pass a path already including .pub-cache?
There was a problem hiding this comment.
Actually this needs to change after my last commit. Sorry will update it
There was a problem hiding this comment.
I think you can make this code simpler by skipping this check, and instead going directly down to pub.dartlang.org dir and checking that those exist.
There was a problem hiding this comment.
Same notes about dartdocs should start with a high level summary: https://dart.dev/guides/language/effective-dart/documentation#do-start-doc-comments-with-a-single-sentence-summary
There was a problem hiding this comment.
Is this indented wrong?
There was a problem hiding this comment.
I don't think '' is a valid path, right?
There was a problem hiding this comment.
It is not. What should happens when _platform.environment['HOME'] (or 'LOCALAPPDATA'/'APPDATA') is null? Is it ok to fail? (_platform.environment['HOME']!)
There was a problem hiding this comment.
no, it is valid to not have a home directory. Maybe globalDirectory should be nullable, and in this case it would be null. And then later you treat a null globalDirectory the same as if it didn't exist.
There was a problem hiding this comment.
| /// There is 3 ways to get the pub cache location | |
| /// There are 3 ways for the tool to find a pub cache location: |
There was a problem hiding this comment.
| /// 2) localPath (flutterRoot) but not globalPath ($HOME) .pubCache in which case we use the available (and vice versa). | |
| /// 2) There is a local cache (in the Flutter SDK) but not a global one (in the user's home directory). |
There was a problem hiding this comment.
| /// 3) If both local and global are available joinCaches is called and local deleted | |
| /// 3) If both local and global are available then merge the local into global and return the global. |
There was a problem hiding this comment.
can't you just use entity itself?
There was a problem hiding this comment.
you can just use entity as a file in this block, because of type promotion
There was a problem hiding this comment.
I don't think this can ever not exist--feel free to explain if i'm reading this wrong.
There was a problem hiding this comment.
We need to check if globalDirectory exists, and if not, return the local cache path
There was a problem hiding this comment.
Can we make pubCache non-nullable, and always tell pub where we know the pub cache is?
There was a problem hiding this comment.
The problem comes if the localPubCache and the globalPubCache are both empty we still need to depend on pub's logic to create the global and skip setting the PUB_CACHE environment variable
There was a problem hiding this comment.
can we rename the function _getPubCacheIfAvailable() and have it return the global cache if we have one?
Fixes #53833
Pre-launch Checklist
///).