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 {
80
80
this . fanout = fanout
81
81
this . blockSizes = blockSizes || [ ]
82
82
this . mtime = mtime || new Date ( 0 )
83
- this . mode = mode
83
+ this . mode = mode || mode === 0 ? ( mode & 0xFFF ) : undefined
84
+ this . _originalMode = mode
84
85
85
86
if ( this . mode === undefined && type === 'file' ) {
86
87
this . mode = DEFAULT_FILE_MODE
@@ -151,8 +152,8 @@ class Data {
151
152
152
153
let mode
153
154
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 )
156
157
157
158
if ( mode === DEFAULT_FILE_MODE && this . type === 'file' ) {
158
159
mode = undefined
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ const directory = loadFixture('test/fixtures/directory.unixfs')
13
13
const file = loadFixture ( 'test/fixtures/file.txt.unixfs' )
14
14
const symlink = loadFixture ( 'test/fixtures/symlink.txt.unixfs' )
15
15
const { Buffer } = require ( 'buffer' )
16
+ const protons = require ( 'protons' )
17
+ const unixfsData = protons ( require ( '../src/unixfs.proto' ) ) . Data
16
18
17
19
describe ( 'unixfs-format' , ( ) => {
18
20
it ( 'defaults to file' , ( ) => {
@@ -145,6 +147,20 @@ describe('unixfs-format', () => {
145
147
expect ( UnixFS . unmarshal ( data . marshal ( ) ) ) . to . have . deep . property ( 'mtime' , new Date ( Math . round ( mtime . getTime ( ) / 1000 ) * 1000 ) )
146
148
} )
147
149
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
+
148
164
// figuring out what is this metadata for https://github.com/ipfs/js-ipfs-data-importing/issues/3#issuecomment-182336526
149
165
it . skip ( 'metadata' , ( ) => { } )
150
166
You can’t perform that action at this time.
0 commit comments