Merge branch 'main' into go1.16_fs3
This commit is contained in:
+20
-10
@@ -3,31 +3,41 @@ package squashfs
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"io/fs"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (w Writer) countInodes() (out uint32) {
|
||||
out++ // for the root indode
|
||||
for _, fold := range w.folders {
|
||||
out += uint32(len(w.structure[fold]))
|
||||
func (w *Writer) fixFolders() error {
|
||||
for folder := range w.structure {
|
||||
if folder == "/" || w.Contains(folder) {
|
||||
continue
|
||||
}
|
||||
err := w.AddFolderTo(folder, fs.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
//WriteTo attempts to write the archive to the given io.Writer.
|
||||
func (w *Writer) WriteTo(write io.WriteSeeker) (int64, error) {
|
||||
//Folder that aren't present (such as if you add a file at /folder/file, but not the folder /folder)
|
||||
//are added with full permission (777).
|
||||
func (w *Writer) WriteTo(write io.Writer) (int64, error) {
|
||||
err := w.fixFolders()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if w.BlockSize > 1048576 {
|
||||
w.BlockSize = 1048576
|
||||
} else if w.BlockSize < 4096 {
|
||||
w.BlockSize = 4096
|
||||
}
|
||||
w.Flags.Duplicates = false
|
||||
w.Flags.RemoveDuplicates = false
|
||||
w.Flags.Exportable = false
|
||||
w.Flags.NoXattr = true
|
||||
//TODO: set forced Flag values
|
||||
//TODO: make sure we aren't missing folders
|
||||
super := superblock{
|
||||
w.superblock = superblock{
|
||||
Magic: magic,
|
||||
InodeCount: w.countInodes(),
|
||||
CreationTime: uint32(time.Now().Unix()),
|
||||
|
||||
Reference in New Issue
Block a user