···11+use std::io::IsTerminal;
12use std::path::PathBuf;
23use std::sync::Arc;
34···57585859impl PushContext {
5960 async fn push_static(self, paths: Vec<PathBuf>) -> Result<()> {
6161+ if paths.is_empty() {
6262+ eprintln!("🤷 Nothing specified.");
6363+ if !std::io::stdin().is_terminal() {
6464+ eprintln!(
6565+ "Hint: Pass --stdin to read the list of store paths from standard input."
6666+ );
6767+ }
6868+ return Ok(());
6969+ }
7070+6071 let roots = paths
6172 .into_iter()
6273 .map(|p| self.store.follow_store_path(p))
···108119 let stdin = BufReader::new(io::stdin());
109120 let mut lines = stdin.lines();
110121 while let Some(line) = lines.next_line().await? {
122122+ if line.is_empty() {
123123+ continue;
124124+ }
125125+111126 let path = self.store.follow_store_path(line)?;
112127 session.queue_many(vec![path])?;
113128 }
···167182 };
168183169184 if sub.stdin {
185185+ if !sub.paths.is_empty() {
186186+ return Err(anyhow!(
187187+ "No paths can be specified on the command line with --stdin"
188188+ ));
189189+ }
190190+170191 push_ctx.push_stdin().await?;
171192 } else {
172193 push_ctx.push_static(sub.paths.clone()).await?;
+21-2
integration-tests/basic/default.nix
···203203204204 with subtest("Check that we can push a path"):
205205 client.succeed("${makeTestDerivation} test.nix")
206206- test_file = client.succeed("nix-build --no-out-link test.nix")
206206+ test_file = client.succeed("nix-build --no-out-link test.nix").strip()
207207 test_file_hash = test_file.removeprefix("/nix/store/")[:32]
208208209209 client.succeed(f"attic push test {test_file}")
210210 client.succeed(f"nix-store --delete {test_file}")
211211- client.fail(f"grep hello {test_file}")
211211+ client.fail(f"ls {test_file}")
212212213213 with subtest("Check that we can pull a path"):
214214 client.succeed("attic use readonly:test")
···218218 with subtest("Check that we cannot push without required permissions"):
219219 client.fail(f"attic push readonly:test {test_file}")
220220 client.fail(f"attic push anon:test {test_file} 2>&1")
221221+222222+ with subtest("Check that we can push a list of paths from stdin"):
223223+ paths = []
224224+ for i in range(10):
225225+ client.succeed(f"${makeTestDerivation} seq{i}.nix")
226226+ path = client.succeed(f"nix-build --no-out-link seq{i}.nix").strip()
227227+ client.succeed(f"echo {path} >>paths.txt")
228228+ paths.append(path)
229229+230230+ client.succeed("attic push test --stdin <paths.txt 2>&1")
231231+232232+ for path in paths:
233233+ client.succeed(f"nix-store --delete {path}")
234234+235235+ with subtest("Check that we can pull the paths back"):
236236+ for path in paths:
237237+ client.fail(f"ls {path}")
238238+ client.succeed(f"nix-store -r {path}")
239239+ client.succeed(f"grep hello {path}")
221240222241 with subtest("Check that we can make the cache public"):
223242 client.fail("curl -sL --fail-with-body http://server:8080/test/nix-cache-info")