From 162b22888119638f99aa2c69ac7c1f448209dc64 Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Fri, 1 Jan 2021 10:54:09 -0600 Subject: [PATCH] Some beginning work on squashfs.Writer Just laying out some of the functions and what they do. --- README.md | 4 ++-- go.mod | 8 ++++---- go.sum | 12 ++++++------ writer.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 writer.go diff --git a/README.md b/README.md index 5311178..791abc8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Currently has support for reading squashfs files and extracting files and folder The only major thing missing from squashfs reading is Xattr parsing. -Special thanks to https://dr-emann.github.io/squashfs/ for some VERY important information in an easy to understand format. +Special thanks to for some VERY important information in an easy to understand format. Thanks also to [distri's squashfs library](https://github.com/distr1/distri/tree/master/internal/squashfs) as I referenced it to figure some things out (and double check others). -# [TODO](https://github.com/CalebQ42/squashfs/projects/1?fullscreen=true) \ No newline at end of file +## [TODO](https://github.com/CalebQ42/squashfs/projects/1?fullscreen=true) diff --git a/go.mod b/go.mod index 3765da2..7376fb4 100644 --- a/go.mod +++ b/go.mod @@ -7,12 +7,12 @@ require ( github.com/adrg/xdg v0.2.3 // indirect github.com/google/go-cmp v0.5.4 // indirect github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect - github.com/klauspost/compress v1.11.3 + github.com/klauspost/compress v1.11.4 github.com/kr/text v0.2.0 // indirect - github.com/pierrec/lz4/v4 v4.1.1 + github.com/pierrec/lz4/v4 v4.1.2 github.com/smartystreets/assertions v1.2.0 // indirect - github.com/ulikunitz/xz v0.5.8 + github.com/ulikunitz/xz v0.5.9 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect -) +) \ No newline at end of file diff --git a/go.sum b/go.sum index 00c259a..65ccf1c 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3 github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/klauspost/compress v1.11.3 h1:dB4Bn0tN3wdCzQxnS8r06kV74qN/TAfaIS0bVE8h3jc= -github.com/klauspost/compress v1.11.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/klauspost/compress v1.11.4 h1:kz40R/YWls3iqT9zX9AHN3WoVsrAWVyui5sxuLqiXqU= +github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -29,8 +29,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/pierrec/lz4/v4 v4.1.1 h1:cS6aGkNLJr4u+UwaA21yp+gbWN3WJWtKo1axmPDObMA= -github.com/pierrec/lz4/v4 v4.1.1/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/pierrec/lz4/v4 v4.1.2 h1:qvY3YFXRQE/XB8MlLzJH7mSzBs74eA2gg52YTk6jUPM= +github.com/pierrec/lz4/v4 v4.1.2/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= @@ -42,8 +42,8 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ= -github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= +github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I= +github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= go.lsp.dev/uri v0.3.0 h1:KcZJmh6nFIBeJzTugn5JTU6OOyG0lDOo3R9KwTxTYbo= go.lsp.dev/uri v0.3.0/go.mod h1:P5sbO1IQR+qySTWOCnhnK7phBx+W3zbLqSMDJNTw88I= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= diff --git a/writer.go b/writer.go new file mode 100644 index 0000000..06ce484 --- /dev/null +++ b/writer.go @@ -0,0 +1,56 @@ +package squashfs + +import ( + "errors" + "os" + + "github.com/CalebQ42/squashfs/internal/inode" +) + +//Writer is an interface to write a squashfs. Doesn't write until you call Write (TODO: maybe not do Write...) +type Writer struct { + files map[string]*File + directories []string +} + +func convertFile(file *os.File) (*File, error) { + stat, err := file.Stat() + if err != nil { + return nil, err + } + var filType int + if stat.IsDir() { + //TODO + } else if stat.Mode().IsRegular() { + filType = inode.BasicFileType + return &File{ + Reader: file, + name: file.Name(), + filType: filType, + }, nil + } else if stat.Mode()&os.ModeSymlink == os.ModeSymlink { + //TODO: implement symlink support + return nil, errors.New("No symlink support. No support at all actually...") + } + return nil, errors.New("File type is NOT supported") +} + +//AddFilesToPath adds the give os.Files to the given path within the squashfs archive. +func (w *Writer) AddFilesToPath(squashfsPath string, files ...*os.File) error { + //TODO + return errors.New("Don't") +} + +//AddFiles adds all files given to the root directory +func (w *Writer) AddFiles(files ...*os.File) error { + //TODO + return errors.New("Don't") +} + +//RemoveFileAt removes the file at filepath from the Writer. +//If multiple files match the given filepath (such as if there are wildcards), all matching files are removed. +//If one or more files are removed, returns true. +func (w *Writer) RemoveFileAt(filepath string) bool { + //TODO + return false +}