File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,8 @@ class Data {
8080 this . fanout = fanout
8181 this . blockSizes = blockSizes || [ ]
8282 this . mtime = mtime || new Date ( 0 )
83- this . mode = mode
83+ this . mode = mode || mode === 0 ? ( mode & 0xFFF ) : undefined
84+ this . _originalMode = mode
8485
8586 if ( this . mode === undefined && type === 'file' ) {
8687 this . mode = DEFAULT_FILE_MODE
@@ -151,8 +152,8 @@ class Data {
151152
152153 let mode
153154
154- if ( ! isNaN ( parseInt ( this . mode ) ) ) {
155- mode = this . mode
155+ if ( this . mode || this . mode === 0 ) {
156+ mode = ( this . _originalMode & 0xFFFFF000 ) | ( this . mode & 0xFFF )
156157
157158 if ( mode === DEFAULT_FILE_MODE && this . type === 'file' ) {
158159 mode = undefined
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ const directory = loadFixture('test/fixtures/directory.unixfs')
1313const file = loadFixture ( 'test/fixtures/file.txt.unixfs' )
1414const symlink = loadFixture ( 'test/fixtures/symlink.txt.unixfs' )
1515const { Buffer } = require ( 'buffer' )
16+ const protons = require ( 'protons' )
17+ const unixfsData = protons ( require ( '../src/unixfs.proto' ) ) . Data
1618
1719describe ( 'unixfs-format' , ( ) => {
1820 it ( 'defaults to file' , ( ) => {
@@ -145,6 +147,20 @@ describe('unixfs-format', () => {
145147 expect ( UnixFS . unmarshal ( data . marshal ( ) ) ) . to . have . deep . property ( 'mtime' , new Date ( Math . round ( mtime . getTime ( ) / 1000 ) * 1000 ) )
146148 } )
147149
150+ it ( 'does not overwrite unknown mode bits' , ( ) => {
151+ const mode = 0xFFFFFFF // larger than currently defined mode bits
152+ const buf = unixfsData . encode ( {
153+ Type : 0 ,
154+ mode
155+ } )
156+
157+ const unmarshaled = UnixFS . unmarshal ( buf )
158+ const marshaled = unmarshaled . marshal ( )
159+
160+ const entry = unixfsData . decode ( marshaled )
161+ expect ( entry ) . to . have . property ( 'mode' , mode )
162+ } )
163+
148164 // figuring out what is this metadata for https://github.com/ipfs/js-ipfs-data-importing/issues/3#issuecomment-182336526
149165 it . skip ( 'metadata' , ( ) => { } )
150166
You can’t perform that action at this time.
0 commit comments