A fork of attic a self-hostable Nix Binary Cache server
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

client/push: Misc fixes

authored by

Zhaofeng Li and committed by
GitHub
1b298162 880ca6d4

+42 -2
+21
client/src/command/push.rs
··· 1 + use std::io::IsTerminal; 1 2 use std::path::PathBuf; 2 3 use std::sync::Arc; 3 4 ··· 57 58 58 59 impl PushContext { 59 60 async fn push_static(self, paths: Vec<PathBuf>) -> Result<()> { 61 + if paths.is_empty() { 62 + eprintln!("🤷 Nothing specified."); 63 + if !std::io::stdin().is_terminal() { 64 + eprintln!( 65 + "Hint: Pass --stdin to read the list of store paths from standard input." 66 + ); 67 + } 68 + return Ok(()); 69 + } 70 + 60 71 let roots = paths 61 72 .into_iter() 62 73 .map(|p| self.store.follow_store_path(p)) ··· 108 119 let stdin = BufReader::new(io::stdin()); 109 120 let mut lines = stdin.lines(); 110 121 while let Some(line) = lines.next_line().await? { 122 + if line.is_empty() { 123 + continue; 124 + } 125 + 111 126 let path = self.store.follow_store_path(line)?; 112 127 session.queue_many(vec![path])?; 113 128 } ··· 167 182 }; 168 183 169 184 if sub.stdin { 185 + if !sub.paths.is_empty() { 186 + return Err(anyhow!( 187 + "No paths can be specified on the command line with --stdin" 188 + )); 189 + } 190 + 170 191 push_ctx.push_stdin().await?; 171 192 } else { 172 193 push_ctx.push_static(sub.paths.clone()).await?;
+21 -2
integration-tests/basic/default.nix
··· 203 203 204 204 with subtest("Check that we can push a path"): 205 205 client.succeed("${makeTestDerivation} test.nix") 206 - test_file = client.succeed("nix-build --no-out-link test.nix") 206 + test_file = client.succeed("nix-build --no-out-link test.nix").strip() 207 207 test_file_hash = test_file.removeprefix("/nix/store/")[:32] 208 208 209 209 client.succeed(f"attic push test {test_file}") 210 210 client.succeed(f"nix-store --delete {test_file}") 211 - client.fail(f"grep hello {test_file}") 211 + client.fail(f"ls {test_file}") 212 212 213 213 with subtest("Check that we can pull a path"): 214 214 client.succeed("attic use readonly:test") ··· 218 218 with subtest("Check that we cannot push without required permissions"): 219 219 client.fail(f"attic push readonly:test {test_file}") 220 220 client.fail(f"attic push anon:test {test_file} 2>&1") 221 + 222 + with subtest("Check that we can push a list of paths from stdin"): 223 + paths = [] 224 + for i in range(10): 225 + client.succeed(f"${makeTestDerivation} seq{i}.nix") 226 + path = client.succeed(f"nix-build --no-out-link seq{i}.nix").strip() 227 + client.succeed(f"echo {path} >>paths.txt") 228 + paths.append(path) 229 + 230 + client.succeed("attic push test --stdin <paths.txt 2>&1") 231 + 232 + for path in paths: 233 + client.succeed(f"nix-store --delete {path}") 234 + 235 + with subtest("Check that we can pull the paths back"): 236 + for path in paths: 237 + client.fail(f"ls {path}") 238 + client.succeed(f"nix-store -r {path}") 239 + client.succeed(f"grep hello {path}") 221 240 222 241 with subtest("Check that we can make the cache public"): 223 242 client.fail("curl -sL --fail-with-body http://server:8080/test/nix-cache-info")