Skip to content

Commit a352777

Browse files
authored
Merge pull request #1758 from stgraber/main
incus/file: Always use 1MB chunks for SFTP
2 parents be0301a + fc9a2b5 commit a352777

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

cmd/incus/file.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,9 +1006,16 @@ func (c *cmdFile) sftpCreateFile(sftpConn *sftp.Client, targetPath string, args
10061006
defer func() { _ = file.Close() }()
10071007

10081008
if push {
1009-
_, err = io.Copy(file, args.Content)
1010-
if err != nil {
1011-
return err
1009+
for {
1010+
// Read 1MB at a time.
1011+
_, err = io.CopyN(file, args.Content, 1024*1024)
1012+
if err != nil {
1013+
if err == io.EOF {
1014+
break
1015+
}
1016+
1017+
return err
1018+
}
10121019
}
10131020
}
10141021

@@ -1126,10 +1133,17 @@ func (c *cmdFile) recursivePullFile(sftpConn *sftp.Client, p string, targetDir s
11261133
},
11271134
}
11281135

1129-
_, err = io.Copy(writer, src)
1130-
if err != nil {
1131-
progress.Done("")
1132-
return err
1136+
for {
1137+
// Read 1MB at a time.
1138+
_, err = io.CopyN(writer, src, 1024*1024)
1139+
if err != nil {
1140+
if err == io.EOF {
1141+
break
1142+
}
1143+
1144+
progress.Done("")
1145+
return err
1146+
}
11331147
}
11341148

11351149
err = src.Close()

internal/server/instance/drivers/driver_lxc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,10 @@ type lxc struct {
441441
var idmapLock sync.Mutex
442442

443443
func (d *lxc) findIdmap() (*idmap.Set, int64, error) {
444+
if d.state.OS.IdmapSet == nil {
445+
return nil, 0, fmt.Errorf("System doesn't have a functional idmap setup")
446+
}
447+
444448
idmapSize := func(size string) (int64, error) {
445449
var idMapSize int64
446450
if size == "" || size == "auto" {

0 commit comments

Comments
 (0)