This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 20 files changed +218
-173
lines changed Expand file tree Collapse file tree 20 files changed +218
-173
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,18 @@ Loading this module through a script tag will make the `mfs` obj available in th
58
58
<script src =" https://npmcdn.com/ipfs-mfs/dist/index.js" ></script >
59
59
```
60
60
61
+ ### A note on concurrency
62
+
63
+ The mfs works by storing a reference to the root node's CID in LevelDB. LevelDB does not support concurrent access so there are read/write locks around bits of the code that modify the the root node's CID.
64
+
65
+ A lock is kept on the main thread and any requests to read/write from workers or the main thread itself are queued pending release of the lock by the existing holder.
66
+
67
+ Reads are executed together, writes are executed sequentially and prevent any reads from starting.
68
+
69
+ If you are using IPFS in a single process or with the node [ cluster] ( https://nodejs.org/api/cluster.html ) module this should be completely transparent.
70
+
71
+ If you are using [ Web Workers] ( https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API ) there is no way to globally listen to messages sent between workers and the main thread so you will need to also use the [ observable-webworkers] ( https://www.npmjs.com/package/observable-webworkers ) module to ensure the right message transports are set up to allow requesting/releasing the locks.
72
+
61
73
## Contribute
62
74
63
75
All are welcome, please join in!
Original file line number Diff line number Diff line change 9
9
"scripts" : {
10
10
"test" : " cross-env aegir test -f test/browser.js" ,
11
11
"test:node" : " aegir test -t node" ,
12
- "test:browser" : " aegir test -t browser -t webworker -f test/browser.js" ,
12
+ "test:browser" : " aegir test -t browser -f test/browser.js" ,
13
+ "test:webworker" : " aegir test -t webworker -f test/browser.js" ,
13
14
"build" : " aegir build" ,
14
15
"lint" : " aegir lint" ,
15
16
"release" : " aegir release" ,
41
42
"aegir" : " ^13.1.0" ,
42
43
"chai" : " ^4.1.2" ,
43
44
"cross-env" : " ^5.1.4" ,
45
+ "detect-webworker" : " ^1.0.0" ,
44
46
"dirty-chai" : " ^2.0.1" ,
45
- "ipfs" : " ~0.28.2 " ,
47
+ "ipfs" : " ~0.29.0 " ,
46
48
"pre-commit" : " ^1.2.2" ,
47
49
"pre-push" : " ~0.1.1" ,
48
50
"safe-buffer" : " ^5.1.1" ,
63
65
"ipfs-unixfs-engine" : " ~0.29.0" ,
64
66
"is-pull-stream" : " ~0.0.0" ,
65
67
"is-stream" : " ^1.1.0" ,
66
- "key_mutex " : " achingbrain/key_mutex " ,
68
+ "mortice " : " ^1.0.0 " ,
67
69
"promisify-es6" : " ^1.0.3" ,
68
70
"pull-cat" : " ^1.1.11" ,
69
71
"pull-paramap" : " ^1.2.2" ,
Original file line number Diff line number Diff line change @@ -41,14 +41,10 @@ module.exports = {
41
41
hash
42
42
} = argv
43
43
44
- ipfs . files . cp ( source , dest , {
44
+ return ipfs . files . cp ( source , dest , {
45
45
parents,
46
46
format,
47
47
hashAlg : hash
48
- } , ( error ) => {
49
- if ( error ) {
50
- throw error
51
- }
52
48
} )
53
49
}
54
50
}
Original file line number Diff line number Diff line change @@ -17,10 +17,6 @@ module.exports = {
17
17
ipfs
18
18
} = argv
19
19
20
- ipfs . files . flush ( path || FILE_SEPARATOR , { } , ( error ) => {
21
- if ( error ) {
22
- throw error
23
- }
24
- } )
20
+ return ipfs . files . flush ( path || FILE_SEPARATOR , { } )
25
21
}
26
22
}
Original file line number Diff line number Diff line change @@ -30,50 +30,45 @@ module.exports = {
30
30
long
31
31
} = argv
32
32
33
- ipfs . files . ls ( path || FILE_SEPARATOR , {
34
- long
35
- } , ( error , files ) => {
36
- if ( error ) {
37
- throw error
38
- }
39
-
40
- if ( long ) {
41
- const table = [ ]
42
- const lengths = { }
43
-
44
- files . forEach ( link => {
45
- const row = {
46
- name : `${ link . name } ` ,
47
- hash : `${ link . hash } ` ,
48
- size : `${ link . size } `
49
- }
50
-
51
- Object . keys ( row ) . forEach ( key => {
52
- const value = row [ key ]
53
-
54
- lengths [ key ] = lengths [ key ] > value . length ? lengths [ key ] : value . length
33
+ return ipfs . files . ls ( path || FILE_SEPARATOR )
34
+ . then ( files => {
35
+ if ( long ) {
36
+ const table = [ ]
37
+ const lengths = { }
38
+
39
+ files . forEach ( link => {
40
+ const row = {
41
+ name : `${ link . name } ` ,
42
+ hash : `${ link . hash } ` ,
43
+ size : `${ link . size } `
44
+ }
45
+
46
+ Object . keys ( row ) . forEach ( key => {
47
+ const value = row [ key ]
48
+
49
+ lengths [ key ] = lengths [ key ] > value . length ? lengths [ key ] : value . length
50
+ } )
51
+
52
+ table . push ( row )
55
53
} )
56
54
57
- table . push ( row )
58
- } )
55
+ table . forEach ( row => {
56
+ let line = ''
59
57
60
- table . forEach ( row => {
61
- let line = ''
58
+ Object . keys ( row ) . forEach ( key => {
59
+ const value = row [ key ]
62
60
63
- Object . keys ( row ) . forEach ( key => {
64
- const value = row [ key ]
61
+ line += value . padEnd ( lengths [ key ] )
62
+ line += '\t'
63
+ } )
65
64
66
- line += value . padEnd ( lengths [ key ] - value . length )
67
- line += '\t'
65
+ print ( line )
68
66
} )
69
67
70
- print ( line )
71
- } )
72
-
73
- return
74
- }
68
+ return
69
+ }
75
70
76
- files . forEach ( link => print ( link . name ) )
77
- } )
71
+ files . forEach ( link => print ( link . name ) )
72
+ } )
78
73
}
79
74
}
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const {
4
- print,
5
4
asBoolean
6
5
} = require ( './utils' )
7
6
@@ -45,17 +44,11 @@ module.exports = {
45
44
flush
46
45
} = argv
47
46
48
- ipfs . files . mkdir ( path , {
47
+ return ipfs . files . mkdir ( path , {
49
48
parents,
50
49
cidVersion,
51
50
hash,
52
51
flush
53
- } , ( error , result ) => {
54
- if ( error ) {
55
- throw error
56
- }
57
-
58
- print ( result )
59
52
} )
60
53
}
61
54
}
Original file line number Diff line number Diff line change @@ -35,13 +35,9 @@ module.exports = {
35
35
recursive
36
36
} = argv
37
37
38
- ipfs . files . mv ( source , dest , {
38
+ return ipfs . files . mv ( source , dest , {
39
39
parents,
40
40
recursive
41
- } , ( error ) => {
42
- if ( error ) {
43
- throw error
44
- }
45
41
} )
46
42
}
47
43
}
Original file line number Diff line number Diff line change @@ -34,24 +34,28 @@ module.exports = {
34
34
length
35
35
} = argv
36
36
37
- waterfall ( [
38
- ( cb ) => ipfs . files . readPullStream ( path , {
39
- offset,
40
- length
41
- } , cb ) ,
42
- ( stream , cb ) => {
43
- pull (
44
- stream ,
45
- through ( buffer => {
46
- print ( buffer , false )
47
- } ) ,
48
- collect ( cb )
49
- )
50
- }
51
- ] , ( error ) => {
52
- if ( error ) {
53
- throw error
54
- }
37
+ return new Promise ( ( resolve , reject ) => {
38
+ waterfall ( [
39
+ ( cb ) => ipfs . files . readPullStream ( path , {
40
+ offset,
41
+ length
42
+ } , cb ) ,
43
+ ( stream , cb ) => {
44
+ pull (
45
+ stream ,
46
+ through ( buffer => {
47
+ print ( buffer , false )
48
+ } ) ,
49
+ collect ( cb )
50
+ )
51
+ }
52
+ ] , ( error ) => {
53
+ if ( error ) {
54
+ return reject ( error )
55
+ }
56
+
57
+ resolve ( )
58
+ } )
55
59
} )
56
60
}
57
61
}
Original file line number Diff line number Diff line change @@ -26,12 +26,8 @@ module.exports = {
26
26
recursive
27
27
} = argv
28
28
29
- ipfs . files . rm ( path , {
29
+ return ipfs . files . rm ( path , {
30
30
recursive
31
- } , ( error ) => {
32
- if ( error ) {
33
- throw error
34
- }
35
31
} )
36
32
}
37
33
}
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const {
4
- print ,
5
- asBoolean
4
+ asBoolean ,
5
+ print
6
6
} = require ( './utils' )
7
7
8
8
module . exports = {
@@ -54,28 +54,25 @@ Type: <type>`,
54
54
withLocal
55
55
} = argv
56
56
57
- ipfs . files . stat ( path , {
57
+ return ipfs . files . stat ( path , {
58
58
withLocal
59
- } , ( error , stats ) => {
60
- if ( error ) {
61
- throw error
62
- }
63
-
64
- if ( hash ) {
65
- return print ( stats . hash )
66
- }
59
+ } )
60
+ . then ( ( stats ) => {
61
+ if ( hash ) {
62
+ return print ( stats . hash )
63
+ }
67
64
68
- if ( size ) {
69
- return print ( stats . size )
70
- }
65
+ if ( size ) {
66
+ return print ( stats . size )
67
+ }
71
68
72
- print ( format
73
- . replace ( '<hash>' , stats . hash )
74
- . replace ( '<size>' , stats . size )
75
- . replace ( '<cumulsize>' , stats . cumulativeSize )
76
- . replace ( '<childs>' , stats . blocks )
77
- . replace ( '<type>' , stats . type )
78
- )
79
- } )
69
+ print ( format
70
+ . replace ( '<hash>' , stats . hash )
71
+ . replace ( '<size>' , stats . size )
72
+ . replace ( '<cumulsize>' , stats . cumulativeSize )
73
+ . replace ( '<childs>' , stats . blocks )
74
+ . replace ( '<type>' , stats . type )
75
+ )
76
+ } )
80
77
}
81
78
}
You can’t perform that action at this time.
0 commit comments