1
0
Fork 0
mirror of https://github.com/zhaofengli/attic.git synced 2024-12-14 11:57:30 +00:00

Merge pull request #182 from zhaofengli/push-stdin-fixes

client/push: Misc fixes
This commit is contained in:
Zhaofeng Li 2024-10-06 13:03:10 -06:00 committed by GitHub
commit 1b29816235
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 2 deletions

View file

@ -1,3 +1,4 @@
use std::io::IsTerminal;
use std::path::PathBuf;
use std::sync::Arc;
@ -57,6 +58,16 @@ struct PushContext {
impl PushContext {
async fn push_static(self, paths: Vec<PathBuf>) -> Result<()> {
if paths.is_empty() {
eprintln!("🤷 Nothing specified.");
if !std::io::stdin().is_terminal() {
eprintln!(
"Hint: Pass --stdin to read the list of store paths from standard input."
);
}
return Ok(());
}
let roots = paths
.into_iter()
.map(|p| self.store.follow_store_path(p))
@ -108,6 +119,10 @@ impl PushContext {
let stdin = BufReader::new(io::stdin());
let mut lines = stdin.lines();
while let Some(line) = lines.next_line().await? {
if line.is_empty() {
continue;
}
let path = self.store.follow_store_path(line)?;
session.queue_many(vec![path])?;
}
@ -167,6 +182,12 @@ pub async fn run(opts: Opts) -> Result<()> {
};
if sub.stdin {
if !sub.paths.is_empty() {
return Err(anyhow!(
"No paths can be specified on the command line with --stdin"
));
}
push_ctx.push_stdin().await?;
} else {
push_ctx.push_static(sub.paths.clone()).await?;

View file

@ -203,12 +203,12 @@ in {
with subtest("Check that we can push a path"):
client.succeed("${makeTestDerivation} test.nix")
test_file = client.succeed("nix-build --no-out-link test.nix")
test_file = client.succeed("nix-build --no-out-link test.nix").strip()
test_file_hash = test_file.removeprefix("/nix/store/")[:32]
client.succeed(f"attic push test {test_file}")
client.succeed(f"nix-store --delete {test_file}")
client.fail(f"grep hello {test_file}")
client.fail(f"ls {test_file}")
with subtest("Check that we can pull a path"):
client.succeed("attic use readonly:test")
@ -219,6 +219,25 @@ in {
client.fail(f"attic push readonly:test {test_file}")
client.fail(f"attic push anon:test {test_file} 2>&1")
with subtest("Check that we can push a list of paths from stdin"):
paths = []
for i in range(10):
client.succeed(f"${makeTestDerivation} seq{i}.nix")
path = client.succeed(f"nix-build --no-out-link seq{i}.nix").strip()
client.succeed(f"echo {path} >>paths.txt")
paths.append(path)
client.succeed("attic push test --stdin <paths.txt 2>&1")
for path in paths:
client.succeed(f"nix-store --delete {path}")
with subtest("Check that we can pull the paths back"):
for path in paths:
client.fail(f"ls {path}")
client.succeed(f"nix-store -r {path}")
client.succeed(f"grep hello {path}")
with subtest("Check that we can make the cache public"):
client.fail("curl -sL --fail-with-body http://server:8080/test/nix-cache-info")
client.fail(f"curl -sL --fail-with-body http://server:8080/test/{test_file_hash}.narinfo")