forked from lix-project/lix
Merge pull request #4036 from chreekat/b/prefetch-executable
nix-prefetch-url: Add --executable flag
This commit is contained in:
commit
d93b373594
|
@ -51,6 +51,9 @@ Nix store is also printed.
|
||||||
result to the Nix store. The resulting hash can be used with
|
result to the Nix store. The resulting hash can be used with
|
||||||
functions such as Nixpkgs’s `fetchzip` or `fetchFromGitHub`.
|
functions such as Nixpkgs’s `fetchzip` or `fetchFromGitHub`.
|
||||||
|
|
||||||
|
- `--executable`
|
||||||
|
Set the executable bit on the downloaded file.
|
||||||
|
|
||||||
- `--name` *name*
|
- `--name` *name*
|
||||||
Override the name of the file in the Nix store. By default, this is
|
Override the name of the file in the Nix store. By default, this is
|
||||||
`hash-basename`, where *basename* is the last component of *url*.
|
`hash-basename`, where *basename* is the last component of *url*.
|
||||||
|
|
|
@ -57,6 +57,7 @@ static int _main(int argc, char * * argv)
|
||||||
bool fromExpr = false;
|
bool fromExpr = false;
|
||||||
string attrPath;
|
string attrPath;
|
||||||
bool unpack = false;
|
bool unpack = false;
|
||||||
|
bool executable = false;
|
||||||
string name;
|
string name;
|
||||||
|
|
||||||
struct MyArgs : LegacyArgs, MixEvalArgs
|
struct MyArgs : LegacyArgs, MixEvalArgs
|
||||||
|
@ -81,6 +82,8 @@ static int _main(int argc, char * * argv)
|
||||||
}
|
}
|
||||||
else if (*arg == "--unpack")
|
else if (*arg == "--unpack")
|
||||||
unpack = true;
|
unpack = true;
|
||||||
|
else if (*arg == "--executable")
|
||||||
|
executable = true;
|
||||||
else if (*arg == "--name")
|
else if (*arg == "--name")
|
||||||
name = getArg(*arg, arg, end);
|
name = getArg(*arg, arg, end);
|
||||||
else if (*arg != "" && arg->at(0) == '-')
|
else if (*arg != "" && arg->at(0) == '-')
|
||||||
|
@ -175,7 +178,11 @@ static int _main(int argc, char * * argv)
|
||||||
|
|
||||||
/* Download the file. */
|
/* Download the file. */
|
||||||
{
|
{
|
||||||
AutoCloseFD fd = open(tmpFile.c_str(), O_WRONLY | O_CREAT | O_EXCL, 0600);
|
auto mode = 0600;
|
||||||
|
if (executable)
|
||||||
|
mode = 0700;
|
||||||
|
|
||||||
|
AutoCloseFD fd = open(tmpFile.c_str(), O_WRONLY | O_CREAT | O_EXCL, mode);
|
||||||
if (!fd) throw SysError("creating temporary file '%s'", tmpFile);
|
if (!fd) throw SysError("creating temporary file '%s'", tmpFile);
|
||||||
|
|
||||||
FdSink sink(fd.get());
|
FdSink sink(fd.get());
|
||||||
|
@ -201,7 +208,7 @@ static int _main(int argc, char * * argv)
|
||||||
tmpFile = unpacked;
|
tmpFile = unpacked;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto method = unpack ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
|
const auto method = unpack || executable ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
|
||||||
|
|
||||||
auto info = store->addToStoreSlow(name, tmpFile, method, ht, expectedHash);
|
auto info = store->addToStoreSlow(name, tmpFile, method, ht, expectedHash);
|
||||||
storePath = info.path;
|
storePath = info.path;
|
||||||
|
|
Loading…
Reference in a new issue