Write files through ipfs add

This commit is contained in:
aynic.os 2022-12-30 18:55:14 +00:00
parent 3d9cc9db6a
commit 50d62741fc
1 changed files with 27 additions and 12 deletions

View File

@ -179,23 +179,38 @@ static int pifs_read(const char *path, char *buf, size_t count, off_t offset,
static int pifs_write(const char *path, const char *buf, size_t count, static int pifs_write(const char *path, const char *buf, size_t count,
off_t offset, struct fuse_file_info *info) off_t offset, struct fuse_file_info *info)
{ {
int fd[2];
int ret = lseek(info->fh, offset * 2, SEEK_SET); int ret = lseek(info->fh, offset * 2, SEEK_SET);
if (ret == -1) { if (ret == -1) {
return -errno; return -errno;
} }
if(pipe(fd)){
for (size_t i = 0; i < count; i++) { perror("pipe(2) failed");
short index; return -1;
for (index = 0; index < SHRT_MAX; index++) { }
if (get_byte(index) == *buf) { switch(fork()){
break; case -1:
perror("fork(2) failed");
return -1;
case 0:
// child
dup2(fd[0], STDIN_FILENO);
dup2(info->fh, STDOUT_FILENO);
close(fd[0]);
close(fd[1]);
ret = execlp("ipfs", "ipfs", "add", "-q", NULL);
if (ret == -1) {
return -errno;
} }
} break;
ret = write(info->fh, &index, sizeof index); default:
if (ret == -1) { // parent
return -errno; close(fd[0]);
} ret = write(fd[1], buf, sizeof(buf));
buf++; if (ret == -1) {
return -errno;
}
close(fd[1]);
} }
return count; return count;