MCPcopy Create free account
hub / github.com/tailscale/tailscale / copyFile

Function copyFile

tstest/integration/vms/vm_setup_test.go:367–406  ·  view source on GitHub ↗
(t *testing.T, cli *sftp.Client, localSrc, remoteDest string)

Source from the content-addressed store, hash-verified

365}
366
367func copyFile(t *testing.T, cli *sftp.Client, localSrc, remoteDest string) {
368 t.Helper()
369
370 fin, err := os.Open(localSrc)
371 if err != nil {
372 t.Fatalf("can't open: %v", err)
373 }
374 defer fin.Close()
375
376 fi, err := fin.Stat()
377 if err != nil {
378 t.Fatalf("can't stat: %v", err)
379 }
380
381 fout, err := cli.Create(remoteDest)
382 if err != nil {
383 t.Fatalf("can't create output file: %v", err)
384 }
385
386 err = fout.Chmod(fi.Mode())
387 if err != nil {
388 fout.Close()
389 t.Fatalf("can't chmod fout: %v", err)
390 }
391
392 n, err := io.Copy(fout, fin)
393 if err != nil {
394 fout.Close()
395 t.Fatalf("copy failed: %v", err)
396 }
397
398 if fi.Size() != n {
399 t.Fatalf("incorrect number of bytes copied: wanted: %d, got: %d", fi.Size(), n)
400 }
401
402 err = fout.Close()
403 if err != nil {
404 t.Fatalf("can't close fout on remote host: %v", err)
405 }
406}
407
408const metaDataTemplate = `instance-id: {{.ID}}
409local-hostname: {{.Hostname}}`

Callers 3

testDistroMethod · 0.70
copyBinariesMethod · 0.70
TestMITMProxyFunction · 0.70

Calls 9

CreateMethod · 0.80
ModeMethod · 0.80
HelperMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
StatMethod · 0.65
ChmodMethod · 0.65
OpenMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…