Receive and scan requests

This commit is contained in:
2025-05-26 12:30:20 +02:00
parent ad9b5eb1ff
commit e4c8ec9621
2 changed files with 23 additions and 20 deletions

View File

@@ -12,12 +12,12 @@
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
#include "pipedata.h"
#include "locations.h" #include "locations.h"
#include "usermanager.h" #include "usermanager.h"
#define MAXNAMESIZE 255 #define MAXNAMESIZE 255
#define SCAN_DONE_SIG SIGRTMIN #define SCAN_DONE_SIG SIGRTMIN
#define SCAN_CMD_USR "docker exec -ti --user www-data nextcloud /var/www/html/occ files:scan --path="
void initRunningFlag(int shmid) void initRunningFlag(int shmid)
{ {
@@ -72,9 +72,8 @@ int main()
std::string line(buffer.data()); std::string line(buffer.data());
if (line.find('|') == std::string::npos) if (line.find('|') == std::string::npos)
{
continue; continue;
}
std::vector<std::string> x = splitLogFile(line, '|'); std::vector<std::string> x = splitLogFile(line, '|');
std::string user(x.at(USER_LOG_LOCATION)); std::string user(x.at(USER_LOG_LOCATION));
@@ -83,9 +82,11 @@ int main()
std::vector<std::string> users = manager.getFlaggedUsers(); std::vector<std::string> users = manager.getFlaggedUsers();
for (auto it = users.begin(); it != users.end(); ++it) for (std::vector<std::string>::iterator it = users.begin(); it != users.end(); ++it)
{ {
write(p1[1], it->data(), it->size()); int size = it->size();
write(p1[1], &size, sizeof(int));
write(p1[1], it->data(), size * sizeof(char));
} }
} }
@@ -96,11 +97,25 @@ int main()
{ {
close(p1[1]); // write close(p1[1]); // write
std::array<char, MAXNAMESIZE> received; int size;
char *buffer = nullptr;
while (read(p1[0], received.data(), sizeof(char) * MAXNAMESIZE)) while (read(p1[0], &size, sizeof(int)))
{ {
if (buffer == nullptr)
buffer = new char[size];
read(p1[0], buffer, size * sizeof(char));
std::string name(buffer);
system((std::string(SCAN_CMD_USR) + name).data());
if (buffer != nullptr)
{
delete[] buffer;
buffer = nullptr;
}
} }
close(p1[0]); // read close(p1[0]); // read

View File

@@ -1,12 +0,0 @@
#ifndef _PIPDATA_H
#define _PIPDATA_H
#include <string>
struct pipestruct
{
std::string user;
};
#endif // _PIPDATA_H