Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions Sources/Workspace/Workspace+State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ public final class WorkspaceState {
self.storagePath = storageDirectory.appending(component: "workspace-state.json")
self.storage = WorkspaceStateStorage(path: self.storagePath, fileSystem: fileSystem)

// Load the state from disk, if possible.
//
// If the disk operation here fails, we ignore the error here.
// This means if managed dependencies data is corrupted or out of date,
// clients will not see the old data and managed dependencies will be
// reset. However there could be other errors, like permission issues,
// these errors will also be ignored but will surface when clients try
// to save the state.
self.dependencies = Workspace.ManagedDependencies()
self.artifacts = Workspace.ManagedArtifacts()
load(warningHandler: initializationWarningHandler)
}

/// Load the state from disk, if possible.
///
/// If the disk operation here fails, we ignore the error here.
/// This means if managed dependencies data is corrupted or out of date,
/// clients will not see the old data and managed dependencies will be
/// reset. However there could be other errors, like permission issues,
/// these errors will also be ignored but will surface when clients try
/// to save the state.
func load(warningHandler: (String) -> Void) {
do {
let storedState = try self.storage.load()
self.dependencies = storedState.dependencies
Expand All @@ -55,7 +61,7 @@ public final class WorkspaceState {
self.dependencies = Workspace.ManagedDependencies()
self.artifacts = Workspace.ManagedArtifacts()
try? self.storage.reset()
initializationWarningHandler("unable to restore workspace state: \(error)")
warningHandler("unable to restore workspace state: \(error)")
}
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,11 @@ public class Workspace {

extension Workspace {

/// Reload the workspace state from the workspace-state.json file on disk.
public func reloadWorkspaceState(warningHandler: (String) -> Void) {
self.state.load(warningHandler: warningHandler)
}

// deprecated 10/2021
@available(*, deprecated, message: "use observability system APIs instead")
public func edit(packageName: String, path: AbsolutePath? = nil, revision: Revision? = nil, checkoutBranch: String? = nil, diagnostics: DiagnosticsEngine) {
Expand Down