1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00
This commit is contained in:
Zack Scholl 2019-04-11 09:53:48 -07:00
parent 1868531ee7
commit 8eba192a22

View file

@ -8,6 +8,7 @@ import (
"github.com/mattn/go-colorable" "github.com/mattn/go-colorable"
"github.com/pion/webrtc/v2" "github.com/pion/webrtc/v2"
"github.com/pkg/errors"
"github.com/schollz/croc/v5/src/compress" "github.com/schollz/croc/v5/src/compress"
"github.com/schollz/croc/v5/src/crypt" "github.com/schollz/croc/v5/src/crypt"
internalSess "github.com/schollz/croc/v5/src/webrtc/internal/session" internalSess "github.com/schollz/croc/v5/src/webrtc/internal/session"
@ -135,28 +136,28 @@ func (s *Session) receiveData(pathToFile string, fileSize int64) error {
var f *os.File var f *os.File
var errOpen error var errOpen error
f, errOpen = os.OpenFile(pathToFile, os.O_WRONLY, 0666) f, errOpen = os.OpenFile(pathToFile, os.O_WRONLY, 0666)
truncate := false
if errOpen == nil { if errOpen == nil {
stat, _ := f.Stat() stat, _ := f.Stat()
if stat.Size() != fileSize { truncate = stat.Size() != fileSize
err := f.Truncate(fileSize)
if err != nil {
log.Error(err)
return err
}
}
} else { } else {
f, err := os.Create(pathToFile) f, err := os.Create(pathToFile)
if err != nil { if err != nil {
err = errors.Wrap(err, "could not create "+pathToFile)
log.Error(err) log.Error(err)
return err return err
} }
err = f.Truncate(fileSize) truncate = true
}
if trucnate {
err := f.Truncate(fileSize)
if err != nil { if err != nil {
err = errors.Wrap(err, "could not truncate "+pathToFile)
log.Error(err) log.Error(err)
return err return err
} }
} }
defer func() { defer func() {
log.Debugln("Stopped receiving data...") log.Debugln("Stopped receiving data...")
f.Close() f.Close()