mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
initial implementation where toFile also writes to sockets
This commit is contained in:
parent
ce1eba687a
commit
ea9738950d
2 changed files with 35 additions and 16 deletions
|
@ -442,6 +442,18 @@ type copySubData struct {
|
||||||
func copySrcSubProcFunc(proc process, cia copyInitialData, cancel context.CancelFunc, initialMessage Message) func(context.Context, chan Message) error {
|
func copySrcSubProcFunc(proc process, cia copyInitialData, cancel context.CancelFunc, initialMessage Message) func(context.Context, chan Message) error {
|
||||||
pf := func(ctx context.Context, procFuncCh chan Message) error {
|
pf := func(ctx context.Context, procFuncCh chan Message) error {
|
||||||
|
|
||||||
|
// Check if the realpath of the directory and filename specified in the
|
||||||
|
// message are of type unix socket, and if it is we do not add the extra
|
||||||
|
// suffix to the filename.
|
||||||
|
file := filepath.Join(initialMessage.Directory, initialMessage.FileName)
|
||||||
|
|
||||||
|
// Check the file is a unix socket, and if it is we write the
|
||||||
|
// data to the socket instead of writing it to a normal file.
|
||||||
|
fi, err := os.Stat(file)
|
||||||
|
if err == nil {
|
||||||
|
fmt.Printf(" ** DEBUG: STAT ERROR: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
// We want to be able to send the reply message when the copying is done,
|
// We want to be able to send the reply message when the copying is done,
|
||||||
// and also for any eventual errors within the subProcFunc. We want to
|
// and also for any eventual errors within the subProcFunc. We want to
|
||||||
// write these to the same place as the the reply message for the initial
|
// write these to the same place as the the reply message for the initial
|
||||||
|
@ -449,8 +461,10 @@ func copySrcSubProcFunc(proc process, cia copyInitialData, cancel context.Cancel
|
||||||
// individual files.
|
// individual files.
|
||||||
msgForSubReplies := initialMessage
|
msgForSubReplies := initialMessage
|
||||||
msgForSubErrors := initialMessage
|
msgForSubErrors := initialMessage
|
||||||
|
if fi.Mode().Type() != fs.ModeSocket {
|
||||||
msgForSubReplies.FileName = msgForSubReplies.FileName + ".copyreply"
|
msgForSubReplies.FileName = msgForSubReplies.FileName + ".copyreply"
|
||||||
msgForSubErrors.FileName = msgForSubErrors.FileName + ".copyerror"
|
msgForSubErrors.FileName = msgForSubErrors.FileName + ".copyerror"
|
||||||
|
}
|
||||||
|
|
||||||
var chunkNumber = 0
|
var chunkNumber = 0
|
||||||
var lastReadChunk []byte
|
var lastReadChunk []byte
|
||||||
|
|
|
@ -17,12 +17,19 @@ func reqWriteFileOrSocket(isAppend bool, proc process, message Message) error {
|
||||||
fileName, folderTree := selectFileNaming(message, proc)
|
fileName, folderTree := selectFileNaming(message, proc)
|
||||||
file := filepath.Join(folderTree, fileName)
|
file := filepath.Join(folderTree, fileName)
|
||||||
|
|
||||||
|
fmt.Printf("******************* DEBUG: CHECK IF SOCKET OR FILE: %v\n", file)
|
||||||
|
|
||||||
|
// log.Fatalf("EXITING\n")
|
||||||
|
|
||||||
// Check the file is a unix socket, and if it is we write the
|
// Check the file is a unix socket, and if it is we write the
|
||||||
// data to the socket instead of writing it to a normal file.
|
// data to the socket instead of writing it to a normal file.
|
||||||
fi, err := os.Stat(file)
|
fi, err := os.Stat(file)
|
||||||
if err == nil {
|
if err == nil && !os.IsNotExist(err) {
|
||||||
if fi.Mode().Type() == fs.ModeSocket {
|
er := fmt.Errorf("info: reqWriteFileOrSocket: failed to stat file, but will continue: %v", folderTree)
|
||||||
// TODO: Write to socket
|
proc.errorKernel.logDebug(er, proc.configuration)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi != nil && fi.Mode().Type() == fs.ModeSocket {
|
||||||
socket, err := net.Dial("unix", file)
|
socket, err := net.Dial("unix", file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
er := fmt.Errorf("error: methodREQToFile/Append could to open socket file for writing: subject:%v, folderTree: %v, %v", proc.subject, folderTree, err)
|
er := fmt.Errorf("error: methodREQToFile/Append could to open socket file for writing: subject:%v, folderTree: %v, %v", proc.subject, folderTree, err)
|
||||||
|
@ -38,8 +45,6 @@ func reqWriteFileOrSocket(isAppend bool, proc process, message Message) error {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// The file is a normal file and not a socket.
|
// The file is a normal file and not a socket.
|
||||||
// Check if folder structure exist, if not create it.
|
// Check if folder structure exist, if not create it.
|
||||||
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
||||||
|
|
Loading…
Reference in a new issue