Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Fix IPLD paths on Windows #100

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 5 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const CID = require('cids')
const doUntil = require('async/doUntil')
const IPFSRepo = require('ipfs-repo')
const BlockService = require('ipfs-block-service')
const joinPath = require('path').join
const osPathSep = require('path').sep
const path = require('path')
const pullDeferSource = require('pull-defer').source
const pullTraverse = require('pull-traverse')
const map = require('async/map')
Expand All @@ -27,6 +26,9 @@ const ipldEthTx = require('ipld-ethereum').ethTx
const ipldEthTxTrie = require('ipld-ethereum').ethTxTrie
const ipldRaw = require('ipld-raw')

// Always use POSIX format (to avoid Windows-specific issues)
const joinPath = path.posix ? path.posix.join : path.join

function noop () {}

class IPLDResolver {
Expand Down Expand Up @@ -117,12 +119,8 @@ class IPLDResolver {

// this removes occurrences of ./, //, ../
// makes sure that path never starts with ./ or /
// path.join is OS specific. Need to convert back to POSIX format.
if (typeof path === 'string') {
path = joinPath('/', path)
.substr(1)
.split(osPathSep)
.join('/')
path = joinPath('/', path).substr(1)
}

if (path === '' || !path) {
Expand Down