mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
simplified chunk write with Write(b[:n])
This commit is contained in:
parent
0b4356b548
commit
fab3fa38dd
1 changed files with 8 additions and 33 deletions
|
@ -377,18 +377,10 @@ func copySrcSubProcFunc(proc process, cia copyInitialData) func(context.Context,
|
||||||
status = copyDone
|
status = copyDone
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing here!
|
lastReadChunk = b[:n]
|
||||||
if n < cia.SplitChunkSize {
|
|
||||||
bb := make([]byte, n)
|
|
||||||
nr := copy(bb, b[:n])
|
|
||||||
b = bb
|
|
||||||
fmt.Printf(" ********************* DEBUG: copied %v elements, length of b=%v\n", nr, len(b))
|
|
||||||
}
|
|
||||||
|
|
||||||
lastReadChunk = b
|
|
||||||
|
|
||||||
// Create a hash of the bytes
|
// Create a hash of the bytes
|
||||||
hash := sha256.Sum256(b)
|
hash := sha256.Sum256(b[:n])
|
||||||
|
|
||||||
chunkNumber++
|
chunkNumber++
|
||||||
|
|
||||||
|
@ -397,7 +389,7 @@ func copySrcSubProcFunc(proc process, cia copyInitialData) func(context.Context,
|
||||||
|
|
||||||
csa := copySubData{
|
csa := copySubData{
|
||||||
CopyStatus: status,
|
CopyStatus: status,
|
||||||
CopyData: b,
|
CopyData: b[:n],
|
||||||
ChunkNumber: chunkNumber,
|
ChunkNumber: chunkNumber,
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
}
|
}
|
||||||
|
@ -624,8 +616,6 @@ func copyDstSubProcFunc(proc process, cia copyInitialData, message Message) func
|
||||||
Data: csaSer,
|
Data: csaSer,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\n ***** DEBUG: copyDstSubProcFunc: cia.SrcMethod: %v\n\n ", cia.SrcMethod)
|
|
||||||
|
|
||||||
sam, err := newSubjectAndMessage(msg)
|
sam, err := newSubjectAndMessage(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("copyDstProcSubFunc: newSubjectAndMessage failed: %v\n", err)
|
log.Fatalf("copyDstProcSubFunc: newSubjectAndMessage failed: %v\n", err)
|
||||||
|
@ -634,10 +624,6 @@ func copyDstSubProcFunc(proc process, cia copyInitialData, message Message) func
|
||||||
proc.toRingbufferCh <- []subjectAndMessage{sam}
|
proc.toRingbufferCh <- []subjectAndMessage{sam}
|
||||||
|
|
||||||
case copyDone:
|
case copyDone:
|
||||||
fmt.Printf("\n\n\n ************** DEBUG: copyDone \n\n\n")
|
|
||||||
|
|
||||||
// var mainFileData []byte
|
|
||||||
|
|
||||||
func() {
|
func() {
|
||||||
|
|
||||||
// Open the main file that chunks files will be written into.
|
// Open the main file that chunks files will be written into.
|
||||||
|
@ -660,8 +646,6 @@ func copyDstSubProcFunc(proc process, cia copyInitialData, message Message) func
|
||||||
}
|
}
|
||||||
|
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
fmt.Println(path, info.Size())
|
|
||||||
fmt.Printf(" * DEBUG: splitChunkSize: %v\n", cia.SplitChunkSize)
|
|
||||||
fh, err := os.Open(path)
|
fh, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -675,28 +659,18 @@ func copyDstSubProcFunc(proc process, cia copyInitialData, message Message) func
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing here!
|
log.Printf("info: copy: writing content of split chunk file=%v into=%v, size=%v\n", path, filePath, info.Size())
|
||||||
if n < cia.SplitChunkSize {
|
_, err = mainfh.Write(b[:n])
|
||||||
bb := make([]byte, n)
|
|
||||||
nr := copy(bb, b[:n])
|
|
||||||
b = bb
|
|
||||||
fmt.Printf(" ********************* DEBUG: copied %v elements, length of b=%v\n", nr, len(b))
|
|
||||||
}
|
|
||||||
|
|
||||||
// fmt.Printf(" * DEBUG: read: %v\n", b)
|
|
||||||
|
|
||||||
_, err = mainfh.Write(b)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: delete tmp files
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error: copyDstSubProcFunc: combining the file chunks back to original file failed: %v\n", err)
|
log.Printf("error: copyDstSubProcFunc: combining the split file chunks back to original file failed: %v\n", err)
|
||||||
|
|
||||||
// Delete the file we've been trying to write to.
|
// Delete the file we've been trying to write to.
|
||||||
os.Remove(filePath)
|
os.Remove(filePath)
|
||||||
|
@ -713,7 +687,8 @@ func copyDstSubProcFunc(proc process, cia copyInitialData, message Message) func
|
||||||
log.Fatalf("error: copyDstSubProcFunc: remove temp dir failed: %v\n", err)
|
log.Fatalf("error: copyDstSubProcFunc: remove temp dir failed: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Printf("main file contains: %v\n", mainFileData)
|
log.Printf("info: copy: successfully wrote all split chunk files into file=%v\n", filePath)
|
||||||
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue