Tentative de récupération de fichier (problème: récupération bloquante)
This commit is contained in:
@@ -2,7 +2,7 @@ package readers
|
||||
|
||||
import (
|
||||
"StoreBackEnd/pkg/protocol"
|
||||
"bufio"
|
||||
"net"
|
||||
)
|
||||
|
||||
// EraseFileRulePrefix Identifiant de cette règle
|
||||
@@ -29,7 +29,7 @@ func (rule EraseFileRule) GetCmd() string {
|
||||
return rule.Cmd
|
||||
}
|
||||
|
||||
func (rule EraseFileRule) Execute(data string) (string, bool, func(r *bufio.Reader) (string, bool)) {
|
||||
func (rule EraseFileRule) Execute(data string) (string, bool, func(r net.Conn) (string, bool)) {
|
||||
if rule.Match(data) {
|
||||
values := rule.matcher.Parse(data)
|
||||
println(values[1], " est le hash du fichier à supprimer")
|
||||
|
||||
@@ -2,8 +2,10 @@ package readers
|
||||
|
||||
import (
|
||||
"StoreBackEnd/pkg/protocol"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
)
|
||||
|
||||
// SendFileRulePrefix Rule command prefix
|
||||
@@ -31,29 +33,31 @@ func (rule SendFileRule) GetCmd() string {
|
||||
}
|
||||
|
||||
// Execute the Rule with a string command.
|
||||
func (rule SendFileRule) Execute(data string) (string, bool, func(r *bufio.Reader) (string, bool)) {
|
||||
func (rule SendFileRule) Execute(data string) (string, bool, func(r net.Conn) (string, bool)) {
|
||||
if rule.Match(data) { // TODO : cloture this command.
|
||||
values := rule.matcher.Parse(data)
|
||||
|
||||
// Values
|
||||
fileName := values[1]
|
||||
// fileSize := values[2]
|
||||
// fileContentHash := values[3]
|
||||
|
||||
// print received data
|
||||
println(values[1], " File Name Hash")
|
||||
println(values[2], " File Size")
|
||||
println(values[3], " File Content Hash")
|
||||
|
||||
// function callback
|
||||
callback := func(r *bufio.Reader) (string, bool) {
|
||||
//var fileContent []byte
|
||||
// readedByte := -1
|
||||
/*
|
||||
for readedByte == -1 || readedByte > 0 {
|
||||
readedByte, _ = r.Read(fileContent)
|
||||
println("SendFileRule Reading file ", " - Hey - ", string(readedByte))
|
||||
}
|
||||
callback := func(con net.Conn) (string, bool) {
|
||||
file, _ := os.Create(fmt.Sprintf("D:\\tmp\\%s", fileName))
|
||||
|
||||
*/
|
||||
var fileContent []byte
|
||||
readedCount, err := io.ReadFull(r, fileContent)
|
||||
println("Un test ici : ", readedCount, err)
|
||||
_, err := io.Copy(file, con)
|
||||
println("HEY1")
|
||||
if err != nil {
|
||||
println("Can't copy file")
|
||||
return "SEND_ERROR\r", false
|
||||
}
|
||||
println("HEY2")
|
||||
return "SEND_OK\r", true
|
||||
}
|
||||
return "SEND_OK\r", true, callback
|
||||
|
||||
Reference in New Issue
Block a user