@helia/unixfs 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/src/commands/utils/add-link.d.ts +0 -7
- package/dist/src/commands/utils/add-link.d.ts.map +1 -1
- package/dist/src/commands/utils/add-link.js +97 -128
- package/dist/src/commands/utils/add-link.js.map +1 -1
- package/dist/src/commands/utils/consumable-hash.d.ts +25 -0
- package/dist/src/commands/utils/consumable-hash.d.ts.map +1 -0
- package/dist/src/commands/utils/consumable-hash.js +136 -0
- package/dist/src/commands/utils/consumable-hash.js.map +1 -0
- package/dist/src/commands/utils/hamt-utils.d.ts +17 -20
- package/dist/src/commands/utils/hamt-utils.d.ts.map +1 -1
- package/dist/src/commands/utils/hamt-utils.js +105 -164
- package/dist/src/commands/utils/hamt-utils.js.map +1 -1
- package/dist/src/commands/utils/remove-link.d.ts.map +1 -1
- package/dist/src/commands/utils/remove-link.js +35 -91
- package/dist/src/commands/utils/remove-link.js.map +1 -1
- package/dist/src/commands/utils/resolve.d.ts.map +1 -1
- package/dist/src/commands/utils/resolve.js +5 -2
- package/dist/src/commands/utils/resolve.js.map +1 -1
- package/package.json +3 -3
- package/src/commands/utils/add-link.ts +107 -170
- package/src/commands/utils/consumable-hash.ts +174 -0
- package/src/commands/utils/hamt-utils.ts +140 -226
- package/src/commands/utils/remove-link.ts +38 -110
- package/src/commands/utils/resolve.ts +8 -3
|
@@ -1,94 +1,15 @@
|
|
|
1
1
|
import * as dagPB from '@ipld/dag-pb';
|
|
2
|
-
import { Bucket, createHAMT } from 'hamt-sharding';
|
|
3
2
|
import { DirSharded } from './dir-sharded.js';
|
|
4
3
|
import { logger } from '@libp2p/logger';
|
|
5
4
|
import { UnixFS } from 'ipfs-unixfs';
|
|
6
5
|
import last from 'it-last';
|
|
7
6
|
import { hamtHashCode, hamtHashFn, hamtBucketBits } from './hamt-constants.js';
|
|
8
7
|
import { persist } from './persist.js';
|
|
8
|
+
import { wrapHash } from './consumable-hash.js';
|
|
9
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
10
|
+
// @ts-expect-error no types
|
|
11
|
+
import SparseArray from 'sparse-array';
|
|
9
12
|
const log = logger('helia:unixfs:commands:utils:hamt-utils');
|
|
10
|
-
export const updateHamtDirectory = async (pbNode, blockstore, bucket, options) => {
|
|
11
|
-
if (pbNode.Data == null) {
|
|
12
|
-
throw new Error('Could not update HAMT directory because parent had no data');
|
|
13
|
-
}
|
|
14
|
-
// update parent with new bit field
|
|
15
|
-
const node = UnixFS.unmarshal(pbNode.Data);
|
|
16
|
-
const dir = new UnixFS({
|
|
17
|
-
type: 'hamt-sharded-directory',
|
|
18
|
-
data: Uint8Array.from(bucket._children.bitField().reverse()),
|
|
19
|
-
fanout: BigInt(bucket.tableSize()),
|
|
20
|
-
hashType: hamtHashCode,
|
|
21
|
-
mode: node.mode,
|
|
22
|
-
mtime: node.mtime
|
|
23
|
-
});
|
|
24
|
-
const updatedPbNode = {
|
|
25
|
-
Data: dir.marshal(),
|
|
26
|
-
Links: pbNode.Links
|
|
27
|
-
};
|
|
28
|
-
const buf = dagPB.encode(dagPB.prepare(updatedPbNode));
|
|
29
|
-
const cid = await persist(buf, blockstore, options);
|
|
30
|
-
return {
|
|
31
|
-
node: updatedPbNode,
|
|
32
|
-
cid,
|
|
33
|
-
size: pbNode.Links.reduce((sum, link) => sum + (link.Tsize ?? 0), buf.byteLength)
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
export const recreateHamtLevel = async (blockstore, links, rootBucket, parentBucket, positionAtParent, options) => {
|
|
37
|
-
// recreate this level of the HAMT
|
|
38
|
-
const bucket = new Bucket({
|
|
39
|
-
hash: rootBucket._options.hash,
|
|
40
|
-
bits: rootBucket._options.bits
|
|
41
|
-
}, parentBucket, positionAtParent);
|
|
42
|
-
parentBucket._putObjectAt(positionAtParent, bucket);
|
|
43
|
-
await addLinksToHamtBucket(blockstore, links, bucket, rootBucket, options);
|
|
44
|
-
return bucket;
|
|
45
|
-
};
|
|
46
|
-
export const recreateInitialHamtLevel = async (links) => {
|
|
47
|
-
const bucket = createHAMT({
|
|
48
|
-
hashFn: hamtHashFn,
|
|
49
|
-
bits: hamtBucketBits
|
|
50
|
-
});
|
|
51
|
-
// populate sub bucket but do not recurse as we do not want to load the whole shard
|
|
52
|
-
await Promise.all(links.map(async (link) => {
|
|
53
|
-
const linkName = (link.Name ?? '');
|
|
54
|
-
if (linkName.length === 2) {
|
|
55
|
-
const pos = parseInt(linkName, 16);
|
|
56
|
-
const subBucket = new Bucket({
|
|
57
|
-
hash: bucket._options.hash,
|
|
58
|
-
bits: bucket._options.bits
|
|
59
|
-
}, bucket, pos);
|
|
60
|
-
bucket._putObjectAt(pos, subBucket);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
await bucket.put(linkName.substring(2), {
|
|
64
|
-
size: link.Tsize,
|
|
65
|
-
cid: link.Hash
|
|
66
|
-
});
|
|
67
|
-
}));
|
|
68
|
-
return bucket;
|
|
69
|
-
};
|
|
70
|
-
export const addLinksToHamtBucket = async (blockstore, links, bucket, rootBucket, options) => {
|
|
71
|
-
await Promise.all(links.map(async (link) => {
|
|
72
|
-
const linkName = (link.Name ?? '');
|
|
73
|
-
if (linkName.length === 2) {
|
|
74
|
-
log('Populating sub bucket', linkName);
|
|
75
|
-
const pos = parseInt(linkName, 16);
|
|
76
|
-
const block = await blockstore.get(link.Hash, options);
|
|
77
|
-
const node = dagPB.decode(block);
|
|
78
|
-
const subBucket = new Bucket({
|
|
79
|
-
hash: rootBucket._options.hash,
|
|
80
|
-
bits: rootBucket._options.bits
|
|
81
|
-
}, bucket, pos);
|
|
82
|
-
bucket._putObjectAt(pos, subBucket);
|
|
83
|
-
await addLinksToHamtBucket(blockstore, node.Links, subBucket, rootBucket, options);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
await rootBucket.put(linkName.substring(2), {
|
|
87
|
-
size: link.Tsize,
|
|
88
|
-
cid: link.Hash
|
|
89
|
-
});
|
|
90
|
-
}));
|
|
91
|
-
};
|
|
92
13
|
export const toPrefix = (position) => {
|
|
93
14
|
return position
|
|
94
15
|
.toString(16)
|
|
@@ -96,87 +17,6 @@ export const toPrefix = (position) => {
|
|
|
96
17
|
.padStart(2, '0')
|
|
97
18
|
.substring(0, 2);
|
|
98
19
|
};
|
|
99
|
-
export const generatePath = async (root, name, blockstore, options) => {
|
|
100
|
-
// start at the root bucket and descend, loading nodes as we go
|
|
101
|
-
const rootBucket = await recreateInitialHamtLevel(root.node.Links);
|
|
102
|
-
const position = await rootBucket._findNewBucketAndPos(name);
|
|
103
|
-
const path = [{
|
|
104
|
-
bucket: position.bucket,
|
|
105
|
-
prefix: toPrefix(position.pos)
|
|
106
|
-
}];
|
|
107
|
-
let currentBucket = position.bucket;
|
|
108
|
-
while (currentBucket !== rootBucket) {
|
|
109
|
-
path.push({
|
|
110
|
-
bucket: currentBucket,
|
|
111
|
-
prefix: toPrefix(currentBucket._posAtParent)
|
|
112
|
-
});
|
|
113
|
-
if (currentBucket._parent == null) {
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
currentBucket = currentBucket._parent;
|
|
117
|
-
}
|
|
118
|
-
// add the root bucket to the path
|
|
119
|
-
path.push({
|
|
120
|
-
bucket: rootBucket,
|
|
121
|
-
node: root.node
|
|
122
|
-
});
|
|
123
|
-
path.reverse();
|
|
124
|
-
// load PbNode for each path segment
|
|
125
|
-
for (let i = 1; i < path.length; i++) {
|
|
126
|
-
const segment = path[i];
|
|
127
|
-
const previousSegment = path[i - 1];
|
|
128
|
-
if (previousSegment.node == null) {
|
|
129
|
-
throw new Error('Could not generate HAMT path');
|
|
130
|
-
}
|
|
131
|
-
// find prefix in links
|
|
132
|
-
const link = previousSegment.node.Links
|
|
133
|
-
.filter(link => (link.Name ?? '').substring(0, 2) === segment.prefix)
|
|
134
|
-
.pop();
|
|
135
|
-
// entry was not in shard
|
|
136
|
-
if (link == null) {
|
|
137
|
-
// reached bottom of tree, file will be added to the current bucket
|
|
138
|
-
log(`Link ${segment.prefix}${name} will be added`);
|
|
139
|
-
// return path
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
const linkName = link.Name ?? '';
|
|
143
|
-
// found entry
|
|
144
|
-
if (linkName === `${segment.prefix}${name}`) {
|
|
145
|
-
log(`Link ${segment.prefix}${name} will be replaced`);
|
|
146
|
-
// file already existed, file will be added to the current bucket
|
|
147
|
-
// return path
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
// found subshard
|
|
151
|
-
log(`Found subshard ${segment.prefix}`);
|
|
152
|
-
const block = await blockstore.get(link.Hash);
|
|
153
|
-
const node = segment.node = dagPB.decode(block);
|
|
154
|
-
// subshard hasn't been loaded, descend to the next level of the HAMT
|
|
155
|
-
if (path[i + 1] == null) {
|
|
156
|
-
log(`Loaded new subshard ${segment.prefix}`);
|
|
157
|
-
if (segment.bucket == null || segment.prefix == null) {
|
|
158
|
-
throw new Error('Shard was invalid');
|
|
159
|
-
}
|
|
160
|
-
await recreateHamtLevel(blockstore, node.Links, rootBucket, segment.bucket, parseInt(segment.prefix, 16), options);
|
|
161
|
-
const position = await rootBucket._findNewBucketAndPos(name);
|
|
162
|
-
// i--
|
|
163
|
-
path.push({
|
|
164
|
-
bucket: position.bucket,
|
|
165
|
-
prefix: toPrefix(position.pos),
|
|
166
|
-
node
|
|
167
|
-
});
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
if (segment.bucket == null) {
|
|
171
|
-
throw new Error('Shard was invalid');
|
|
172
|
-
}
|
|
173
|
-
// add intermediate links to bucket
|
|
174
|
-
await addLinksToHamtBucket(blockstore, node.Links, segment.bucket, rootBucket, options);
|
|
175
|
-
}
|
|
176
|
-
await rootBucket.put(name, true);
|
|
177
|
-
path.reverse();
|
|
178
|
-
return path;
|
|
179
|
-
};
|
|
180
20
|
export const createShard = async (blockstore, contents, options) => {
|
|
181
21
|
const shard = new DirSharded({
|
|
182
22
|
root: true,
|
|
@@ -201,4 +41,105 @@ export const createShard = async (blockstore, contents, options) => {
|
|
|
201
41
|
}
|
|
202
42
|
return res;
|
|
203
43
|
};
|
|
44
|
+
export const updateShardedDirectory = async (path, blockstore, options) => {
|
|
45
|
+
// persist any metadata on the shard root
|
|
46
|
+
const shardRoot = UnixFS.unmarshal(path[0].node.Data ?? new Uint8Array(0));
|
|
47
|
+
// this is always the same
|
|
48
|
+
const fanout = BigInt(Math.pow(2, hamtBucketBits));
|
|
49
|
+
// start from the leaf and ascend to the root
|
|
50
|
+
path.reverse();
|
|
51
|
+
let cid;
|
|
52
|
+
let node;
|
|
53
|
+
for (let i = 0; i < path.length; i++) {
|
|
54
|
+
const isRoot = i === path.length - 1;
|
|
55
|
+
const segment = path[i];
|
|
56
|
+
// go-ipfs uses little endian, that's why we have to
|
|
57
|
+
// reverse the bit field before storing it
|
|
58
|
+
const data = Uint8Array.from(segment.children.bitField().reverse());
|
|
59
|
+
const dir = new UnixFS({
|
|
60
|
+
type: 'hamt-sharded-directory',
|
|
61
|
+
data,
|
|
62
|
+
fanout,
|
|
63
|
+
hashType: hamtHashCode
|
|
64
|
+
});
|
|
65
|
+
if (isRoot) {
|
|
66
|
+
dir.mtime = shardRoot.mtime;
|
|
67
|
+
dir.mode = shardRoot.mode;
|
|
68
|
+
}
|
|
69
|
+
node = {
|
|
70
|
+
Data: dir.marshal(),
|
|
71
|
+
Links: segment.node.Links
|
|
72
|
+
};
|
|
73
|
+
const block = dagPB.encode(dagPB.prepare(node));
|
|
74
|
+
cid = await persist(block, blockstore, options);
|
|
75
|
+
if (!isRoot) {
|
|
76
|
+
// update link in parent sub-shard
|
|
77
|
+
const nextSegment = path[i + 1];
|
|
78
|
+
if (nextSegment == null) {
|
|
79
|
+
throw new Error('Was not operating on shard root but also had no parent?');
|
|
80
|
+
}
|
|
81
|
+
log('updating link in parent sub-shard with prefix %s', nextSegment.prefix);
|
|
82
|
+
nextSegment.node.Links = nextSegment.node.Links.filter(l => l.Name !== nextSegment.prefix);
|
|
83
|
+
nextSegment.node.Links.push({
|
|
84
|
+
Name: nextSegment.prefix,
|
|
85
|
+
Hash: cid,
|
|
86
|
+
Tsize: segment.node.Links.reduce((acc, curr) => acc + (curr.Tsize ?? 0), block.byteLength)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (cid == null || node == null) {
|
|
91
|
+
throw new Error('Noting persisted');
|
|
92
|
+
}
|
|
93
|
+
return { cid, node };
|
|
94
|
+
};
|
|
95
|
+
export const recreateShardedDirectory = async (cid, fileName, blockstore, options) => {
|
|
96
|
+
const wrapped = wrapHash(hamtHashFn);
|
|
97
|
+
const hash = wrapped(uint8ArrayFromString(fileName));
|
|
98
|
+
const path = [];
|
|
99
|
+
// descend the HAMT, loading each layer as we head towards the target child
|
|
100
|
+
while (true) {
|
|
101
|
+
const block = await blockstore.get(cid, options);
|
|
102
|
+
const node = dagPB.decode(block);
|
|
103
|
+
const children = new SparseArray();
|
|
104
|
+
const index = await hash.take(hamtBucketBits);
|
|
105
|
+
const prefix = toPrefix(index);
|
|
106
|
+
path.push({
|
|
107
|
+
prefix,
|
|
108
|
+
children,
|
|
109
|
+
node
|
|
110
|
+
});
|
|
111
|
+
let childLink;
|
|
112
|
+
// update sparsearray child layout - the bitfield is used as the data field for the
|
|
113
|
+
// intermediate DAG node so this is required to generate consistent hashes
|
|
114
|
+
for (const link of node.Links) {
|
|
115
|
+
const linkName = link.Name ?? '';
|
|
116
|
+
if (linkName.length < 2) {
|
|
117
|
+
throw new Error('Invalid HAMT - link name was too short');
|
|
118
|
+
}
|
|
119
|
+
const position = parseInt(linkName.substring(0, 2), 16);
|
|
120
|
+
children.set(position, true);
|
|
121
|
+
// we found the child we are looking for
|
|
122
|
+
if (linkName.startsWith(prefix)) {
|
|
123
|
+
childLink = link;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (childLink == null) {
|
|
127
|
+
log('no link found with prefix %s for %s', prefix, fileName);
|
|
128
|
+
// hash.untake(hamtBucketBits)
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
const linkName = childLink.Name ?? '';
|
|
132
|
+
if (linkName.length < 2) {
|
|
133
|
+
throw new Error('Invalid HAMT - link name was too short');
|
|
134
|
+
}
|
|
135
|
+
if (linkName.length === 2) {
|
|
136
|
+
// found sub-shard
|
|
137
|
+
cid = childLink.Hash;
|
|
138
|
+
log('descend into sub-shard with prefix %s', linkName);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
return { path, hash };
|
|
144
|
+
};
|
|
204
145
|
//# sourceMappingURL=hamt-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hamt-utils.js","sourceRoot":"","sources":["../../../../src/commands/utils/hamt-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,
|
|
1
|
+
{"version":3,"file":"hamt-utils.js","sourceRoot":"","sources":["../../../../src/commands/utils/hamt-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,IAAI,MAAM,SAAS,CAAA;AAE1B,OAAO,EACL,YAAY,EACZ,UAAU,EACV,cAAc,EACf,MAAM,qBAAqB,CAAA;AAK5B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAgB,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,4BAA4B;AAC5B,OAAO,W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;aACjB;SACF;QAED,IAAI,SAAS,IAAI,IAAI,EAAE;YACrB,GAAG,CAAC,qCAAqC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;YAC5D,8BAA8B;YAC9B,MAAK;SACN;QAED,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,IAAI,EAAE,CAAA;QAErC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;SAC1D;QAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,kBAAkB;YAClB,GAAG,GAAG,SAAS,CAAC,IAAI,CAAA;YACpB,GAAG,CAAC,uCAAuC,EAAE,QAAQ,CAAC,CAAA;YAEtD,SAAQ;SACT;QAED,MAAK;KACN;IAED,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AACvB,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-link.d.ts","sourceRoot":"","sources":["../../../../src/commands/utils/remove-link.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"remove-link.d.ts","sourceRoot":"","sources":["../../../../src/commands/utils/remove-link.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAQpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAQtD,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,wBAAwB,EAAE,MAAM,CAAA;IAChC,UAAU,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,GAAG,CAAA;CACT;AAED,wBAAsB,UAAU,CAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAwB5I"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as dagPB from '@ipld/dag-pb';
|
|
2
2
|
import { logger } from '@libp2p/logger';
|
|
3
3
|
import { UnixFS } from 'ipfs-unixfs';
|
|
4
|
-
import {
|
|
4
|
+
import { recreateShardedDirectory, updateShardedDirectory } from './hamt-utils.js';
|
|
5
5
|
import { InvalidParametersError, InvalidPBNodeError } from './errors.js';
|
|
6
6
|
import { exporter } from 'ipfs-unixfs-exporter';
|
|
7
7
|
import { persist } from './persist.js';
|
|
@@ -41,102 +41,46 @@ const removeFromDirectory = async (parent, name, blockstore, options) => {
|
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
43
|
const removeFromShardedDirectory = async (parent, name, blockstore, options) => {
|
|
44
|
-
const path = await
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
throw new Error('Could not generate HAMT path');
|
|
44
|
+
const { path } = await recreateShardedDirectory(parent.cid, name, blockstore, options);
|
|
45
|
+
const finalSegment = path[path.length - 1];
|
|
46
|
+
if (finalSegment == null) {
|
|
47
|
+
throw new Error('Invalid HAMT, could not generate path');
|
|
49
48
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
throw new InvalidParametersError('Path segment had no associated PBNode');
|
|
65
|
-
}
|
|
66
|
-
const link = segment.node.Links
|
|
67
|
-
.find(link => (link.Name ?? '').substring(0, 2) === lastPrefix);
|
|
68
|
-
if (link == null) {
|
|
69
|
-
throw new InvalidParametersError(`No link found with prefix ${lastPrefix} for file ${name}`);
|
|
70
|
-
}
|
|
71
|
-
if (link.Name == null) {
|
|
72
|
-
throw new InvalidParametersError(`${lastPrefix} link had no name`);
|
|
73
|
-
}
|
|
74
|
-
if (link.Name === fileName) {
|
|
75
|
-
log(`removing existing link ${link.Name}`);
|
|
76
|
-
const links = segment.node.Links.filter((nodeLink) => {
|
|
77
|
-
return nodeLink.Name !== link.Name;
|
|
78
|
-
});
|
|
79
|
-
if (segment.bucket == null) {
|
|
80
|
-
throw new Error('Segment bucket was missing');
|
|
81
|
-
}
|
|
82
|
-
await segment.bucket.del(name);
|
|
83
|
-
const result = await updateHamtDirectory({
|
|
84
|
-
Data: segment.node.Data,
|
|
85
|
-
Links: links
|
|
86
|
-
}, blockstore, segment.bucket, options);
|
|
87
|
-
segment.node = result.node;
|
|
88
|
-
segment.cid = result.cid;
|
|
89
|
-
segment.size = result.size;
|
|
90
|
-
}
|
|
91
|
-
if (link.Name === lastPrefix) {
|
|
92
|
-
log(`updating subshard with prefix ${lastPrefix}`);
|
|
93
|
-
const lastSegment = path[i - 1];
|
|
94
|
-
if (lastSegment.node?.Links.length === 1) {
|
|
95
|
-
log(`removing subshard for ${lastPrefix}`);
|
|
96
|
-
// convert subshard back to normal file entry
|
|
97
|
-
const link = lastSegment.node.Links[0];
|
|
98
|
-
link.Name = `${lastPrefix}${(link.Name ?? '').substring(2)}`;
|
|
99
|
-
// remove existing prefix
|
|
100
|
-
segment.node.Links = segment.node.Links.filter((link) => {
|
|
101
|
-
return link.Name !== lastPrefix;
|
|
102
|
-
});
|
|
103
|
-
// add new child
|
|
104
|
-
segment.node.Links.push(link);
|
|
49
|
+
const linkName = finalSegment.node.Links.filter(l => (l.Name ?? '').substring(2) === name).map(l => l.Name).pop();
|
|
50
|
+
if (linkName == null) {
|
|
51
|
+
throw new Error('File not found');
|
|
52
|
+
}
|
|
53
|
+
const prefix = linkName.substring(0, 2);
|
|
54
|
+
const index = parseInt(prefix, 16);
|
|
55
|
+
// remove the file from the shard
|
|
56
|
+
finalSegment.node.Links = finalSegment.node.Links.filter(link => link.Name !== linkName);
|
|
57
|
+
finalSegment.children.unset(index);
|
|
58
|
+
if (finalSegment.node.Links.length === 1) {
|
|
59
|
+
// replace the subshard with the last remaining file in the parent
|
|
60
|
+
while (true) {
|
|
61
|
+
if (path.length === 1) {
|
|
62
|
+
break;
|
|
105
63
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// remove existing prefix
|
|
110
|
-
segment.node.Links = segment.node.Links.filter((link) => {
|
|
111
|
-
return link.Name !== lastPrefix;
|
|
112
|
-
});
|
|
113
|
-
if (lastSegment.cid == null) {
|
|
114
|
-
throw new Error('Did not persist previous segment');
|
|
115
|
-
}
|
|
116
|
-
// add new child
|
|
117
|
-
segment.node.Links.push({
|
|
118
|
-
Name: lastPrefix,
|
|
119
|
-
Hash: lastSegment.cid,
|
|
120
|
-
Tsize: lastSegment.size
|
|
121
|
-
});
|
|
64
|
+
const segment = path[path.length - 1];
|
|
65
|
+
if (segment == null || segment.node.Links.length > 1) {
|
|
66
|
+
break;
|
|
122
67
|
}
|
|
123
|
-
|
|
124
|
-
|
|
68
|
+
// remove final segment
|
|
69
|
+
path.pop();
|
|
70
|
+
const nextSegment = path[path.length - 1];
|
|
71
|
+
if (nextSegment == null) {
|
|
72
|
+
break;
|
|
125
73
|
}
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
74
|
+
const link = segment.node.Links[0];
|
|
75
|
+
nextSegment.node.Links = nextSegment.node.Links.filter(l => !(l.Name ?? '').startsWith(nextSegment.prefix));
|
|
76
|
+
nextSegment.node.Links.push({
|
|
77
|
+
Hash: link.Hash,
|
|
78
|
+
Name: `${nextSegment.prefix}${(link.Name ?? '').substring(2)}`,
|
|
79
|
+
Tsize: link.Tsize
|
|
80
|
+
});
|
|
130
81
|
}
|
|
131
82
|
}
|
|
132
|
-
|
|
133
|
-
if (rootSegment == null || rootSegment.cid == null || rootSegment.node == null) {
|
|
134
|
-
throw new InvalidParametersError('Failed to update shard');
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
cid: rootSegment.cid,
|
|
138
|
-
node: rootSegment.node
|
|
139
|
-
};
|
|
83
|
+
return await updateShardedDirectory(path, blockstore, options);
|
|
140
84
|
};
|
|
141
85
|
const convertToFlatDirectory = async (parent, blockstore, options) => {
|
|
142
86
|
if (parent.node.Data == null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-link.js","sourceRoot":"","sources":["../../../../src/commands/utils/remove-link.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"remove-link.js","sourceRoot":"","sources":["../../../../src/commands/utils/remove-link.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EACL,wBAAwB,EAExB,sBAAsB,EACvB,MAAM,iBAAiB,CAAA;AAKxB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AAEnE,MAAM,GAAG,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAA;AAYpD,MAAM,CAA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,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../../src/commands/utils/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAMtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAItD,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,GAAG,CAAA;IACR,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,GAAG,EAAE,GAAG,CAAA;IAER,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;CACrB;AAED,wBAAsB,OAAO,CAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CA2DxI;AAED,MAAM,WAAW,qBAAsB,SAAQ,YAAY;IACzD,wBAAwB,EAAE,MAAM,CAAA;CACjC;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,CAoC3I"}
|
|
@@ -4,12 +4,12 @@ import { DoesNotExistError, InvalidParametersError } from './errors.js';
|
|
|
4
4
|
import { addLink } from './add-link.js';
|
|
5
5
|
import { cidToDirectory } from './cid-to-directory.js';
|
|
6
6
|
import { cidToPBLink } from './cid-to-pblink.js';
|
|
7
|
-
const log = logger('helia:unixfs:components:utils:
|
|
7
|
+
const log = logger('helia:unixfs:components:utils:resolve');
|
|
8
8
|
export async function resolve(cid, path, blockstore, options) {
|
|
9
|
-
log('resolve "%s" under %c', path, cid);
|
|
10
9
|
if (path == null || path === '') {
|
|
11
10
|
return { cid };
|
|
12
11
|
}
|
|
12
|
+
log('resolve "%s" under %c', path, cid);
|
|
13
13
|
const parts = path.split('/').filter(Boolean);
|
|
14
14
|
const segments = [{
|
|
15
15
|
name: '',
|
|
@@ -19,6 +19,7 @@ export async function resolve(cid, path, blockstore, options) {
|
|
|
19
19
|
for (let i = 0; i < parts.length; i++) {
|
|
20
20
|
const part = parts[i];
|
|
21
21
|
const result = await exporter(cid, blockstore, options);
|
|
22
|
+
log('resolving "%s"', part, result);
|
|
22
23
|
if (result.type === 'file') {
|
|
23
24
|
if (i < parts.length - 1) {
|
|
24
25
|
throw new InvalidParametersError('Path was invalid');
|
|
@@ -30,6 +31,7 @@ export async function resolve(cid, path, blockstore, options) {
|
|
|
30
31
|
for await (const entry of result.content()) {
|
|
31
32
|
if (entry.name === part) {
|
|
32
33
|
dirCid = entry.cid;
|
|
34
|
+
break;
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
if (dirCid == null) {
|
|
@@ -46,6 +48,7 @@ export async function resolve(cid, path, blockstore, options) {
|
|
|
46
48
|
throw new InvalidParametersError('Could not resolve path');
|
|
47
49
|
}
|
|
48
50
|
}
|
|
51
|
+
log('resolved %s to %c', path, cid);
|
|
49
52
|
return {
|
|
50
53
|
cid,
|
|
51
54
|
path,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../../../src/commands/utils/resolve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,iBAAiB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"Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia-unixfs#readme",
|
|
@@ -139,7 +139,6 @@
|
|
|
139
139
|
"release": "aegir release"
|
|
140
140
|
},
|
|
141
141
|
"dependencies": {
|
|
142
|
-
"@helia/interface": "next",
|
|
143
142
|
"@ipld/dag-pb": "^4.0.0",
|
|
144
143
|
"@libp2p/interfaces": "^3.3.1",
|
|
145
144
|
"@libp2p/logger": "^2.0.5",
|
|
@@ -152,7 +151,8 @@
|
|
|
152
151
|
"it-last": "^2.0.0",
|
|
153
152
|
"it-pipe": "^2.0.5",
|
|
154
153
|
"merge-options": "^3.0.4",
|
|
155
|
-
"multiformats": "^11.0.1"
|
|
154
|
+
"multiformats": "^11.0.1",
|
|
155
|
+
"sparse-array": "^1.3.2"
|
|
156
156
|
},
|
|
157
157
|
"devDependencies": {
|
|
158
158
|
"aegir": "^38.1.0",
|