ipfs / fs-repo-migrations

Migrations for the filesystem repository of ipfs clients
MIT License
58 stars 42 forks source link

ipfs daemon -c PATH --migrate doesn't use supplied path #153

Closed iohzrd closed 2 years ago

iohzrd commented 2 years ago

I use go-ipfs in my project https://github.com/iohzrd/identia. I try to keep IPFS (along with all my dependencies) up-to-date but, i'm having trouble doing so as there isn't a clear way to migrate from v0.11 to v0.12 without manual intervention...

What I've tried so far:

$ ipfs daemon -c /home/user/.config/identia  --migrate
Initializing daemon...
go-ipfs version: 0.12.0
Repo version: 12
System version: amd64/linux
Golang version: go1.16.12
Found outdated fs-repo, migrations need to be run.
The migrations of fs-repo failed:
  stat /home/user/.ipfs: no such file or directory
If you think this is a bug, please file an issue and include this whole log output.
  https://github.com/ipfs/fs-repo-migrations

Error: stat /home/user/.ipfs: no such file or directory

Keep in mind that the migration needs to be done programmatically and not but the user. And, my app does not depend on electron or any node runtime, so using the JS ipfs-repo-migrations package is not an option.

iohzrd commented 2 years ago

I was able to solve my issue by setting the IPFS_PATH environment variable as follows:

pub async fn launch_ipfs_daemon(client: &IpfsClient) -> Result<String, String> {
  println!("Starting IPFS.");
  env::set_var(
    "IPFS_PATH",
    config::identia_app_data_path()
      .into_os_string()
      .to_str()
      .unwrap(),
  );
  Command::new_sidecar("ipfs")
    .or(Err(String::from("Can't find ipfs binary")))?
    .args(&[
      "daemon",
      "-c",
      config::identia_app_data_path()
        .into_os_string()
        .to_str()
        .unwrap(),
      "--migrate=true",
    ])
    .spawn()
    .map_err(|err| format!("Failed to execute ipfs: {:?}", err))?;

  match wait_for_ipfs_ready(&client).await {
    Ok(ready) => println!("ipfs ready: {:?}", ready),
    Err(e) => eprintln!("error waiting for ipfs: {}", e),
  }

  match get_ipfs_id(&client).await {
    Ok(id) => Ok(id),
    Err(e) => Err(e),
  }
}

That being said, it would still be nice to be able to pass the path directly from ipfs to fs-repo-migrations. I'm gonna leave this issue open for now, until I get a response. In the mean time, I may add a note about the env variable to the documentation for those who may encounter a similar issue in the future.

guseggert commented 2 years ago

Using IPFS_PATH is the way to switch repos, -c is only for switching config, so I don't think there's anything to do here.