Skip to content

Commit

Permalink
Merge pull request NixOS#28 from obsidiansystems/better-error-for-ipf…
Browse files Browse the repository at this point in the history
…s-address-mismatch

Better error for ipfs address mismatch
  • Loading branch information
Ericson2314 authored Jun 23, 2020
2 parents 31f6ca8 + c354ba6 commit a02c2a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/libstore/ipfs-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,22 @@ class IPFSBinaryCacheStore : public Store
}

public:
Path formatPathAsProtocol(Path path) {
if (hasPrefix(path, "/ipfs/"))
return "ipfs://" + path.substr(strlen("/ipfs/"), string::npos);
else if (hasPrefix(path, "/ipns/"))
return "ipns://" + path.substr(strlen("/ipfs/"), string::npos);
else return path;
}

// IPNS publish can be slow, we try to do it rarely.
void sync() override
{
auto state(_state.lock());

if (!optIpnsPath) {
throw Error("We don't have an ipns path and the current ipfs address doesn't match the initial one.\n current: %s\n initial: %s",
state->ipfsPath, initialIpfsPath);
throw Error("The current IPFS address doesn't match the configured one. \n initial: %s\n current: %s",
formatPathAsProtocol(initialIpfsPath), formatPathAsProtocol(state->ipfsPath));
}

auto ipnsPath = *optIpnsPath;
Expand Down
2 changes: 1 addition & 1 deletion tests/ipfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ EMPTY_HASH=$(echo {} | ipfs dag put)
IPFS_HASH=$(set -e; \
set -o pipefail; \
! nix copy --to ipfs://$EMPTY_HASH $(nix-build ./fixed.nix -A good) --experimental-features nix-command \
|& grep current: | awk '{print substr($2, 7, length($2))}')
|& grep current: | awk '{print substr($2, 8, length($2))}')

# Verify that new path is valid.
nix copy --to ipfs://$IPFS_HASH $(nix-build ./fixed.nix -A good) --experimental-features nix-command
Expand Down

0 comments on commit a02c2a5

Please sign in to comment.