Skip to content

Commit

Permalink
Unlink + save working
Browse files Browse the repository at this point in the history
  • Loading branch information
taralesca committed Jan 13, 2019
1 parent 6f134b8 commit 8724044
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
9 changes: 1 addition & 8 deletions sifs.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,7 @@ int main(int argc, char **argv) {
else {
logger(DEBUG, "[main] Opened file: %s\n", argv[argc - 1]);
}
if ((fdd = open("testy.tar", O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) {
logger(DEBUG, "[main] File2 open error(%s): %d\n", "testy.tar", errno);
return -1;
}
else {
logger(DEBUG, "[main] Opened file2: %s\n", "testy.tar");
}


argument = malloc(strlen(argv[argc-1]));
strcpy(argument, argv[argc-1]);
// Moving reading head to beginning of file
Expand Down
23 changes: 23 additions & 0 deletions src/destroy.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#include "../lib/destroy.h"
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
int fd; /* gets value from sifs.c */
int fdd;
int enfd;
Expand Down Expand Up @@ -58,6 +67,20 @@ void print_tree2(struct node *n) {
}

void sifs_destroy(void* private_data) {

off_t ofs = lseek(fd, 0, SEEK_END);
printf("\n\n\n\n\n\n%d\n\n\n\n\n", ofs);
lseek(fd, 0, SEEK_SET);
int crt = 0;
while(crt < ofs) {
crt += write(fd, "\0", ofs);
printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", crt);
}
//~ printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", write(fd, "\0", ofs));
//~ printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", write(fd, "\0", ofs));
//~ printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", write(fd, "\0", ofs));
//~ printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", write(fd, "\0", ofs));
//printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", write(fd, "\0", ofs));

lseek(fd, 0, SEEK_SET); /* move to the beginning of file */
//~ printf("FAILED!!!");
Expand Down
1 change: 1 addition & 0 deletions src/unlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ int sifs_unlink(const char* path) {
del_index = i;
}
}

free(deleted);
for (int i = del_index + 1; i < parent->children_size; i++) {
parent->children[i-1] = parent->children[i];
Expand Down

0 comments on commit 8724044

Please sign in to comment.