Merge pull request #35 from gradha/pr_fail_bad_input
Adds verification of whitelisted files and directories.
This commit is contained in:
commit
4a764b1f87
1 changed files with 18 additions and 5 deletions
|
|
@ -190,7 +190,8 @@ proc copyWithExt(origDir, currentDir, dest: string, pkgInfo: TPackageInfo) =
|
||||||
createDir(changeRoot(origDir, dest, path).splitFile.dir)
|
createDir(changeRoot(origDir, dest, path).splitFile.dir)
|
||||||
copyFileD(path, changeRoot(origDir, dest, path))
|
copyFileD(path, changeRoot(origDir, dest, path))
|
||||||
|
|
||||||
proc copyFilesRec(origDir, currentDir, dest: string, pkgInfo: TPackageInfo) =
|
proc copyFilesRec(origDir, currentDir, dest: string,
|
||||||
|
options: TOptions, pkgInfo: TPackageInfo) =
|
||||||
## Copies all the required files, skips files specified in the .babel file
|
## Copies all the required files, skips files specified in the .babel file
|
||||||
## (TPackageInfo).
|
## (TPackageInfo).
|
||||||
let whitelistMode =
|
let whitelistMode =
|
||||||
|
|
@ -199,11 +200,23 @@ proc copyFilesRec(origDir, currentDir, dest: string, pkgInfo: TPackageInfo) =
|
||||||
pkgInfo.installExt.len != 0
|
pkgInfo.installExt.len != 0
|
||||||
if whitelistMode:
|
if whitelistMode:
|
||||||
for file in pkgInfo.installFiles:
|
for file in pkgInfo.installFiles:
|
||||||
|
let src = origDir / file
|
||||||
|
if not src.existsFile():
|
||||||
|
if options.prompt("Missing file " & src & ". Continue?"):
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
quit(QuitSuccess)
|
||||||
createDir(dest / file.splitFile.dir)
|
createDir(dest / file.splitFile.dir)
|
||||||
copyFileD(origDir / file, dest / file)
|
copyFileD(src, dest / file)
|
||||||
|
|
||||||
for dir in pkgInfo.installDirs:
|
for dir in pkgInfo.installDirs:
|
||||||
# TODO: Allow skipping files inside dirs?
|
# TODO: Allow skipping files inside dirs?
|
||||||
|
let src = origDir / dir
|
||||||
|
if not src.existsDir():
|
||||||
|
if options.prompt("Missing directory " & src & ". Continue?"):
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
quit(QuitSuccess)
|
||||||
copyDirD(origDir / dir, dest / dir)
|
copyDirD(origDir / dir, dest / dir)
|
||||||
|
|
||||||
copyWithExt(origDir, currentDir, dest, pkgInfo)
|
copyWithExt(origDir, currentDir, dest, pkgInfo)
|
||||||
|
|
@ -216,7 +229,7 @@ proc copyFilesRec(origDir, currentDir, dest: string, pkgInfo: TPackageInfo) =
|
||||||
# Create the dir.
|
# Create the dir.
|
||||||
createDir(changeRoot(origDir, dest, file))
|
createDir(changeRoot(origDir, dest, file))
|
||||||
|
|
||||||
copyFilesRec(origDir, file, dest, pkgInfo)
|
copyFilesRec(origDir, file, dest, options, pkgInfo)
|
||||||
else:
|
else:
|
||||||
let skip = pkgInfo.checkInstallFile(origDir, file)
|
let skip = pkgInfo.checkInstallFile(origDir, file)
|
||||||
|
|
||||||
|
|
@ -305,7 +318,7 @@ proc installFromDir(dir: string, latest: bool, options: TOptions, url: string):
|
||||||
if pkgInfo.bin.len > 0:
|
if pkgInfo.bin.len > 0:
|
||||||
createDir(binDir)
|
createDir(binDir)
|
||||||
# Copy all binaries and files that are not skipped
|
# Copy all binaries and files that are not skipped
|
||||||
copyFilesRec(realDir, realDir, pkgDestDir, pkgInfo)
|
copyFilesRec(realDir, realDir, pkgDestDir, options, pkgInfo)
|
||||||
# Set file permissions to +x for all binaries built,
|
# Set file permissions to +x for all binaries built,
|
||||||
# and symlink them on *nix OS' to $babelDir/bin/
|
# and symlink them on *nix OS' to $babelDir/bin/
|
||||||
for bin in pkgInfo.bin:
|
for bin in pkgInfo.bin:
|
||||||
|
|
@ -328,7 +341,7 @@ proc installFromDir(dir: string, latest: bool, options: TOptions, url: string):
|
||||||
else:
|
else:
|
||||||
{.error: "Sorry, your platform is not supported.".}
|
{.error: "Sorry, your platform is not supported.".}
|
||||||
else:
|
else:
|
||||||
copyFilesRec(realDir, realDir, pkgDestDir, pkgInfo)
|
copyFilesRec(realDir, realDir, pkgDestDir, options, pkgInfo)
|
||||||
|
|
||||||
# Save a babelmeta.json file.
|
# Save a babelmeta.json file.
|
||||||
var babelmeta = %{"url": %url}
|
var babelmeta = %{"url": %url}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue