Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved IPFS lock from js to rust #392

Merged
merged 1 commit into from
Jul 14, 2023
Merged
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
14 changes: 0 additions & 14 deletions executor/src/core/PerspectivismCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,6 @@ export default class PerspectivismCore {

async initIPFS(params: InitIPFSParams) {
console.log("Init IPFS service with port ", params.ipfsSwarmPort, " at path: ", params.ipfsRepoPath);
let basePath = params.ipfsRepoPath ? params.ipfsRepoPath : path.join(this.#config.dataPath, "ipfs");
let repoPath = path.join(basePath, "repo.lock");
console.log("Check if repo.lock exists at: ", repoPath);

let retries = 0;
while (fs.existsSync(repoPath)) {
await sleep(1000);
retries++;
if (retries >= 10) {
console.log("Waited long enough for repo.lock to be released, deleting...");
fs.rmdirSync(repoPath, { recursive: true });
fs.rmSync(path.join(basePath, "datastore", "LOCK"));
}
}

let ipfs = await IPFS.init(params.ipfsSwarmPort, params.ipfsRepoPath);
this.#IPFS = ipfs;
Expand Down
12 changes: 12 additions & 0 deletions ui/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ fn main() {
let _ = remove_dir_all(data_path());
}

let mut waited_seconds = 0;
while data_path().join("ipfs").join("repo.lock").exists() {
println!("IPFS repo.lock exists, waiting...");
std::thread::sleep(std::time::Duration::from_secs(1));
waited_seconds = waited_seconds + 1;
if waited_seconds > 10 {
println!("Waited long enough, removing lock...");
let _ = remove_dir_all(data_path().join("ipfs").join("repo.lock"));
let _ = remove_dir_all(data_path().join("ipfs").join("datastore").join("LOCK"));
}
}

if let Err(err) = setup_logs() {
println!("Error setting up the logs: {:?}", err);
}
Expand Down