Skip to content

Commit

Permalink
update get-filetype to use known list of compressed extnames
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Sep 6, 2021
1 parent 60fec8d commit f4de3d5
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions packages/app-builder-lib/src/publish/KeygenPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ClientRequest, RequestOptions } from "http"
import { HttpPublisher, PublishContext } from "electron-publish"
import { KeygenOptions } from "builder-util-runtime/out/publishOptions"
import { configureRequestOptions, HttpExecutor, parseJson } from "builder-util-runtime"
import * as path from "path"

export class KeygenPublisher extends HttpPublisher {
readonly providerName = "keygen"
Expand Down Expand Up @@ -118,30 +119,30 @@ export class KeygenPublisher extends HttpPublisher {
// e.g. `zip`, `dmg`, `tar.gz`, `tar.bz2`, `exe.blockmap`. We'd use `path.extname()`,
// but it doesn't support multiple extensions, e.g. `dmg.blockmap`.
private getFiletype(filename: string): string {
const components = filename
.split(".")
.filter(c => c !== "")
.slice(1)
.reverse()
const extnames = []
const regex = new RegExp(
"^" + // Test from start of string.
"(?=.*?[a-z])" + // Must contain at least 1 lowercase letter.
"(?=.*?[0-9]?)" + // May contain optional numbers.
"[a-z0-9]+" + // Must contain only lowercase letters and numbers.
"$" // Test to end of string.
)
let extname = path.extname(filename)

switch (extname) {
// Append leading extension for blockmap filetype
case '.blockmap': {
extname = path.extname(filename.replace(extname, '')) + extname

// Collect extensions, working backwards until we reach a non-extension.
for (const component of components) {
if (!regex.test(component)) {
// We've reached a non-extension (i.e. we've collected all valid extensions).
break
}
// Append leading extension for known compressed tar formats
case '.bz2':
case '.gz':
case '.lz':
case '.xz':
case '.7z': {
const ext = path.extname(filename.replace(extname, ''))
if (ext === '.tar') {
extname = ext + extname
}

extnames.unshift(component)
break
}
}

return extnames.join(".")
return extname
}
}

0 comments on commit f4de3d5

Please sign in to comment.