Skip to content

Commit c7bc240

Browse files
bruce-oneisaacs
authored andcommitted
Fix hardlink extraction with strip.
Ensure we update linkpath if the hardlink target will have its path stripped. Close #195
1 parent 0068764 commit c7bc240

16 files changed

+1669
-1
lines changed

lib/unpack.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ class Unpack extends Parser {
178178
if (parts.length < this.strip)
179179
return false
180180
entry.path = parts.slice(this.strip).join('/')
181+
182+
if (entry.type === 'Link') {
183+
const linkparts = entry.linkpath.split(/\/|\\/)
184+
if (linkparts.length >= this.strip)
185+
entry.linkpath = linkparts.slice(this.strip).join('/')
186+
}
181187
}
182188

183189
if (!this.preservePaths) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this link is like diamond
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this link is like diamond
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this link is like diamond
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hardlink-2
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
[
2+
[
3+
"ignoredEntry",
4+
{
5+
"extended": null,
6+
"globalExtended": null,
7+
"type": "Directory",
8+
"meta": false,
9+
"ignore": true,
10+
"path": "strip-dir/",
11+
"mode": 493,
12+
"uid": 0,
13+
"gid": 0,
14+
"uname": "",
15+
"gname": "",
16+
"size": 0,
17+
"mtime": "2018-11-06T01:45:25.000Z",
18+
"atime": null,
19+
"ctime": null,
20+
"linkpath": "",
21+
"header": {
22+
"cksumValid": true,
23+
"needPax": false,
24+
"path": "strip-dir/",
25+
"mode": 493,
26+
"uid": 0,
27+
"gid": 0,
28+
"size": 0,
29+
"mtime": "2018-11-06T01:45:25.000Z",
30+
"cksum": 4708,
31+
"linkpath": "",
32+
"uname": "",
33+
"gname": "",
34+
"devmaj": 0,
35+
"devmin": 0,
36+
"atime": null,
37+
"ctime": null
38+
}
39+
}
40+
],
41+
[
42+
"ignoredEntry",
43+
{
44+
"extended": null,
45+
"globalExtended": null,
46+
"type": "File",
47+
"meta": false,
48+
"ignore": true,
49+
"path": "strip-dir/hardlink-1",
50+
"mode": 420,
51+
"uid": 0,
52+
"gid": 0,
53+
"uname": "",
54+
"gname": "",
55+
"size": 26,
56+
"mtime": "2018-11-06T01:45:25.000Z",
57+
"atime": null,
58+
"ctime": null,
59+
"linkpath": "",
60+
"header": {
61+
"cksumValid": true,
62+
"needPax": false,
63+
"path": "strip-dir/hardlink-1",
64+
"mode": 420,
65+
"uid": 0,
66+
"gid": 0,
67+
"size": 26,
68+
"mtime": "2018-11-06T01:45:25.000Z",
69+
"cksum": 5644,
70+
"linkpath": "",
71+
"uname": "",
72+
"gname": "",
73+
"devmaj": 0,
74+
"devmin": 0,
75+
"atime": null,
76+
"ctime": null
77+
}
78+
}
79+
],
80+
[
81+
"ignoredEntry",
82+
{
83+
"extended": null,
84+
"globalExtended": null,
85+
"type": "Link",
86+
"meta": false,
87+
"ignore": true,
88+
"path": "strip-dir/hardlink-2",
89+
"mode": 420,
90+
"uid": 0,
91+
"gid": 0,
92+
"uname": "",
93+
"gname": "",
94+
"size": 0,
95+
"mtime": "2018-11-06T01:45:25.000Z",
96+
"atime": null,
97+
"ctime": null,
98+
"linkpath": "strip-dir/hardlink-1",
99+
"header": {
100+
"cksumValid": true,
101+
"needPax": false,
102+
"path": "strip-dir/hardlink-2",
103+
"mode": 420,
104+
"uid": 0,
105+
"gid": 0,
106+
"size": 0,
107+
"mtime": "2018-11-06T01:45:25.000Z",
108+
"cksum": 7553,
109+
"linkpath": "strip-dir/hardlink-1",
110+
"uname": "",
111+
"gname": "",
112+
"devmaj": 0,
113+
"devmin": 0,
114+
"atime": null,
115+
"ctime": null
116+
}
117+
}
118+
],
119+
[
120+
"ignoredEntry",
121+
{
122+
"extended": null,
123+
"globalExtended": null,
124+
"type": "Link",
125+
"meta": false,
126+
"ignore": true,
127+
"path": "strip-dir/1/2/3/hardlink-3",
128+
"mode": 420,
129+
"uid": 0,
130+
"gid": 0,
131+
"uname": "",
132+
"gname": "",
133+
"size": 0,
134+
"mtime": "2018-11-06T01:45:25.000Z",
135+
"atime": null,
136+
"ctime": null,
137+
"linkpath": "strip-dir/hardlink-1",
138+
"header": {
139+
"cksumValid": true,
140+
"needPax": false,
141+
"path": "strip-dir/1/2/3/hardlink-3",
142+
"mode": 420,
143+
"uid": 0,
144+
"gid": 0,
145+
"size": 0,
146+
"mtime": "2018-11-06T01:45:25.000Z",
147+
"cksum": 7845,
148+
"linkpath": "strip-dir/hardlink-1",
149+
"uname": "",
150+
"gname": "",
151+
"devmaj": 0,
152+
"devmin": 0,
153+
"atime": null,
154+
"ctime": null
155+
}
156+
}
157+
],
158+
[
159+
"ignoredEntry",
160+
{
161+
"extended": null,
162+
"globalExtended": null,
163+
"type": "SymbolicLink",
164+
"meta": false,
165+
"ignore": true,
166+
"path": "strip-dir/symlink",
167+
"mode": 420,
168+
"uid": 0,
169+
"gid": 0,
170+
"uname": "",
171+
"gname": "",
172+
"size": 0,
173+
"mtime": "2018-11-06T01:45:25.000Z",
174+
"atime": null,
175+
"ctime": null,
176+
"linkpath": "hardlink-2",
177+
"header": {
178+
"cksumValid": true,
179+
"needPax": false,
180+
"path": "strip-dir/symlink",
181+
"mode": 420,
182+
"uid": 0,
183+
"gid": 0,
184+
"size": 0,
185+
"mtime": "2018-11-06T01:45:25.000Z",
186+
"cksum": 6417,
187+
"linkpath": "hardlink-2",
188+
"uname": "",
189+
"gname": "",
190+
"devmaj": 0,
191+
"devmin": 0,
192+
"atime": null,
193+
"ctime": null
194+
}
195+
}
196+
],
197+
[
198+
"end"
199+
]
200+
]

0 commit comments

Comments
 (0)