Skip to content

Commit

Permalink
Make Memfd library work with mips
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Jun 28, 2024
1 parent f93342f commit 9a849be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.22.4

require (
github.com/ActiveState/termtest/conpty v0.5.0
github.com/NHAS/go-memfd v0.0.0-20170219213707-6e4af0518993
github.com/creack/pty v1.1.21
github.com/fatih/color v1.15.0
github.com/glebarez/sqlite v1.11.0
github.com/go-ping/ping v1.1.0
github.com/justincormack/go-memfd v0.0.0-20170219213707-6e4af0518993
github.com/pkg/sftp v1.13.6
golang.org/x/crypto v0.24.0
golang.org/x/net v0.26.0
Expand All @@ -25,6 +25,7 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/justincormack/go-memfd v0.0.0-20170219213707-6e4af0518993 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/ActiveState/termtest/conpty v0.5.0 h1:JLUe6YDs4Jw4xNPCU+8VwTpniYOGeKz
github.com/ActiveState/termtest/conpty v0.5.0/go.mod h1:LO4208FLsxw6DcNZ1UtuGUMW+ga9PFtX4ntv8Ymg9og=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/NHAS/go-memfd v0.0.0-20170219213707-6e4af0518993 h1:eNW2Elw0JBnLO4GV+JqLyNMNJ5L/tpdaUDsHc5JccSs=
github.com/NHAS/go-memfd v0.0.0-20170219213707-6e4af0518993/go.mod h1:GGyL0NE4G/1d5Qq7VTDFpv/mhgGfMV1DY4jMaas5Y0A=
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
9 changes: 6 additions & 3 deletions pkg/storage/store_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ package storage
import (
"fmt"
"io"
"os"

"github.com/justincormack/go-memfd"
"golang.org/x/sys/unix"
)

func Store(filename string, r io.ReadCloser) (string, error) {

mfd, err := memfd.Create()
fd, err := unix.MemfdCreate("", unix.MFD_CLOEXEC|unix.MFD_ALLOW_SEALING)
if err != nil {
return StoreDisk(filename, r)
}

mfd := os.NewFile(uintptr(fd), "")
_, err = io.Copy(mfd, r)
if err != nil {
return StoreDisk(filename, r)
}

return fmt.Sprintf("/proc/self/fd/%d", mfd.Fd()), nil
return fmt.Sprintf("/proc/self/fd/%d", fd), nil
}

0 comments on commit 9a849be

Please sign in to comment.