feat: Implement basic overwriting, in-memory File.Write

This commit is contained in:
Felicitas Pojtinger
2021-12-22 22:02:12 +01:00
parent 191896bcda
commit 92669961cc
12 changed files with 150 additions and 45 deletions

View File

@@ -25,6 +25,7 @@ func (o *Operations) Update(
getSrc func() (config.FileConfig, error),
compressionLevel string,
replace bool,
skipSizeCheck bool,
) ([]*tar.Header, error) {
o.diskOperationLock.Lock()
defer o.diskOperationLock.Unlock()
@@ -75,7 +76,7 @@ func (o *Operations) Update(
hdr.PAXRecords[records.STFSRecordAction] = records.STFSRecordActionUpdate
var f io.ReadSeekCloser
if file.Info.Mode().IsRegular() && replace && file.Info.Size() > 0 {
if file.Info.Mode().IsRegular() && replace && (file.Info.Size() > 0 || skipSizeCheck) {
// Get the compressed size for the header
fileSizeCounter := &ioext.CounterWriter{
Writer: io.Discard,
@@ -183,7 +184,7 @@ func (o *Operations) Update(
dirty = true
if !file.Info.Mode().IsRegular() || file.Info.Size() <= 0 {
if !file.Info.Mode().IsRegular() || (!skipSizeCheck && file.Info.Size() <= 0) {
if f != nil {
if err := f.Close(); err != nil {
return []*tar.Header{}, err