(listing, expectedNames)
| 106 | } |
| 107 | |
| 108 | function validateExactTarMemberListing(listing, expectedNames) { |
| 109 | if (listing.includes('\0')) { |
| 110 | throw new Error('tar member listing contains a NUL byte'); |
| 111 | } |
| 112 | const members = listing.split(/\r?\n/); |
| 113 | if (members[members.length - 1] === '') members.pop(); |
| 114 | const expected = new Set(expectedNames); |
| 115 | const seen = new Set(); |
| 116 | for (const member of members) { |
| 117 | if (!member || !expected.has(member) || seen.has(member)) { |
| 118 | throw new Error(`archive contains an unexpected or duplicate root member: ${JSON.stringify(member)}`); |
| 119 | } |
| 120 | seen.add(member); |
| 121 | } |
| 122 | if (members.length !== expectedNames.length || seen.size !== expected.size) { |
| 123 | throw new Error( |
| 124 | `archive must contain exactly these root files: ${expectedNames.join(', ')}`, |
| 125 | ); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | function requireRegularArchive(archivePath) { |
| 130 | if (!fs.statSync(archivePath).isFile()) { |
no outgoing calls
no test coverage detected