Added uid/guid support.
Added permission support.
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package squashfs
|
||||||
|
|
||||||
|
import "reflect"
|
||||||
|
|
||||||
|
func (w *Writer) compressData(data []byte) ([]byte, error) {
|
||||||
|
if reflect.DeepEqual(data, make([]byte, len(data))) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
compressedData, err := w.compressor.Compress(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(data) <= len(compressedData) {
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
return compressedData, nil
|
||||||
|
}
|
||||||
@@ -50,9 +50,11 @@ func (g *Gzip) Decompress(r io.Reader) ([]byte, error) {
|
|||||||
//Compress compresses the given data (as a byte array) and returns the compressed data.
|
//Compress compresses the given data (as a byte array) and returns the compressed data.
|
||||||
func (g *Gzip) Compress(data []byte) ([]byte, error) {
|
func (g *Gzip) Compress(data []byte) ([]byte, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
wrt := zlib.NewWriter(&buf)
|
wrt, err := zlib.NewWriterLevel(&buf, int(g.CompressionLevel))
|
||||||
defer wrt.Close()
|
if err != nil {
|
||||||
_, err := wrt.Write(data)
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = wrt.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/CalebQ42/squashfs/internal/compression"
|
"github.com/CalebQ42/squashfs/internal/compression"
|
||||||
)
|
)
|
||||||
@@ -18,6 +20,7 @@ type fileHolder struct {
|
|||||||
symLocation string
|
symLocation string
|
||||||
UID int
|
UID int
|
||||||
GUID int
|
GUID int
|
||||||
|
perm int
|
||||||
folder bool
|
folder bool
|
||||||
symlink bool
|
symlink bool
|
||||||
}
|
}
|
||||||
@@ -28,7 +31,7 @@ type Writer struct {
|
|||||||
compressor compression.Compressor
|
compressor compression.Compressor
|
||||||
structure map[string][]*fileHolder
|
structure map[string][]*fileHolder
|
||||||
symlinkTable map[string]string //[oldpath]newpath
|
symlinkTable map[string]string //[oldpath]newpath
|
||||||
superblock superblock
|
uidGUIDTable []int
|
||||||
compressionType int
|
compressionType int
|
||||||
allowErrors bool
|
allowErrors bool
|
||||||
}
|
}
|
||||||
@@ -87,6 +90,20 @@ func (w *Writer) AddFileTo(filepath string, file *os.File) error {
|
|||||||
}
|
}
|
||||||
holder.folder = stat.IsDir()
|
holder.folder = stat.IsDir()
|
||||||
holder.symlink = (stat.Mode()&os.ModeSymlink == os.ModeSymlink)
|
holder.symlink = (stat.Mode()&os.ModeSymlink == os.ModeSymlink)
|
||||||
|
holder.perm = int(stat.Mode().Perm())
|
||||||
|
//Thanks to https://stackoverflow.com/questions/58179647/getting-uid-and-gid-of-a-file for uid and guid getting
|
||||||
|
if stat, ok := stat.Sys().(*syscall.Stat_t); ok {
|
||||||
|
holder.UID = int(stat.Uid)
|
||||||
|
holder.GUID = int(stat.Gid)
|
||||||
|
}
|
||||||
|
if sort.SearchInts(w.uidGUIDTable, holder.UID) == len(w.uidGUIDTable) {
|
||||||
|
w.uidGUIDTable = append(w.uidGUIDTable, holder.UID)
|
||||||
|
sort.Ints(w.uidGUIDTable)
|
||||||
|
}
|
||||||
|
if sort.SearchInts(w.uidGUIDTable, holder.GUID) == len(w.uidGUIDTable) {
|
||||||
|
w.uidGUIDTable = append(w.uidGUIDTable, holder.GUID)
|
||||||
|
sort.Ints(w.uidGUIDTable)
|
||||||
|
}
|
||||||
if holder.symlink {
|
if holder.symlink {
|
||||||
target, err := os.Readlink(file.Name())
|
target, err := os.Readlink(file.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user