-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix pub get/upgrade with cache for workspace
- Loading branch information
1 parent
49f210a
commit 0ed06c4
Showing
3 changed files
with
82 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
enum PubWorkspaceCacheAction { get, upgrade, downgrade } | ||
|
||
/// Last action done on a workspace, invalide others. | ||
class PubWorkspaceCache { | ||
final String workspaceRoot; | ||
final bool offline; | ||
final PubWorkspaceCacheAction action; | ||
|
||
PubWorkspaceCache(this.workspaceRoot, this.action, this.offline); | ||
|
||
@override | ||
int get hashCode => workspaceRoot.hashCode; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (other is PubWorkspaceCache) { | ||
return workspaceRoot == other.workspaceRoot && | ||
offline == other.offline && | ||
action == other.action; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
/// Workspace cache | ||
abstract class PubWorkspacesCache { | ||
factory PubWorkspacesCache() => _PubWorkspacesCache(); | ||
|
||
/// Returns true if the cache was updated (i.e. must run, next call will return false) | ||
bool cacheIfNeeded(PubWorkspaceCache cache); | ||
PubWorkspaceCache? getWorkspaceCache(String workspaceRoot); | ||
} | ||
|
||
class _PubWorkspacesCache implements PubWorkspacesCache { | ||
final _map = <String, PubWorkspaceCache>{}; | ||
|
||
_PubWorkspacesCache(); | ||
|
||
@override | ||
PubWorkspaceCache? getWorkspaceCache(String workspaceRoot) { | ||
return _map[workspaceRoot]; | ||
} | ||
|
||
@override | ||
bool cacheIfNeeded(PubWorkspaceCache cache) { | ||
var existing = _map[cache.workspaceRoot]; | ||
if (existing != cache) { | ||
_map[cache.workspaceRoot] = cache; | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
PubWorkspacesCache? pubWorkspacesCache; | ||
|
||
/// Internal only use for run_ci binary for now | ||
void initPubWorkspacesCache() { | ||
pubWorkspacesCache = PubWorkspacesCache(); | ||
} |