Skip to content

Commit

Permalink
Added rmdir
Browse files Browse the repository at this point in the history
  • Loading branch information
Dummm committed Jan 13, 2019
1 parent 8724044 commit 1715997
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ sifs: \
src/open.o \
src/read.o \
src/unlink.o \
src/rmdir.o \
src/mknod.o \
src/mkdir.o \
src/destroy.o \
Expand All @@ -52,6 +53,7 @@ sifs: \
src/open.o \
src/read.o \
src/unlink.o \
src/rmdir.o \
src/write.o \
src/destroy.o \
sifs.o
Expand All @@ -72,7 +74,6 @@ tar_structure.o: src/tar_structure.c lib/tar_structure.h
tree.o: src/tree.c lib/tree.h
$(CC) $(CFLAGS) -c tree.c


mkdir.o: src/mkdir.c lib/mkdir.h
$(CC) $(CFLAGS) -c mkdir.c

Expand Down Expand Up @@ -100,6 +101,9 @@ destroy.o: src/destroy.c lib/destroy.h
unlink.o: src/unlink.c lib/unlink.h
$(CC) $(CFLAGS) -c unlink.c

rmdir.o: src/rmdir.c lib/rmdir.h
$(CC) $(CFLAGS) -c rmdir.c

sifs.o: sifs.c lib/tar_structure.h
$(CC) $(CFLAGS) -c sifs.c

Expand Down
15 changes: 15 additions & 0 deletions lib/rmdir.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef rmdir_h
#define rmdir_h
#include "./logger.h" /* logger */
#include <fuse.h> /* fuse_file_info */
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <fuse.h>
#include "tree.h"
#include "logger.h"
#include "tar_structure.h"
int sifs_rmdir(const char* path);
#endif

10 changes: 5 additions & 5 deletions sifs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "lib/mknod.h"
#include "lib/mkdir.h"
#include "lib/unlink.h"
// #include "lib/rmdir.h"
#include "lib/rmdir.h"
// #include "lib/symlink.h"
// #include "lib/rename.h"
// #include "lib/link.h"
Expand Down Expand Up @@ -100,7 +100,7 @@ int populate_tree_directory(int fd, struct node *dir) {
free(auxTar);
break;
}

// Creating node
//auxNode = malloc(sizeof(struct node));
auxNode = calloc(1, sizeof(struct node));
Expand Down Expand Up @@ -246,7 +246,7 @@ static struct fuse_operations sifs_oper = {
.mknod = sifs_mknod,
.mkdir = sifs_mkdir,
.unlink = sifs_unlink,
// .rmdir = sifs_rmdir,
.rmdir = sifs_rmdir,
// .symlink = sifs_symlink,
// .rename = sifs_rename,
// .link = sifs_link,
Expand Down Expand Up @@ -279,9 +279,9 @@ int main(int argc, char **argv) {
else {
logger(DEBUG, "[main] Opened file: %s\n", argv[argc - 1]);
}

argument = malloc(strlen(argv[argc-1]));
strcpy(argument, argv[argc-1]);
strcpy(argument, argv[argc-1]);
// Moving reading head to beginning of file
lseek(fd, 0, SEEK_SET);

Expand Down
6 changes: 3 additions & 3 deletions src/destroy.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ 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);
printf("\n\n\n\n\n\n%ld\n\n\n\n\n", ofs);
lseek(fd, 0, SEEK_SET);
int crt = 0;
while(crt < ofs) {
Expand All @@ -85,7 +85,7 @@ void sifs_destroy(void* private_data) {
lseek(fd, 0, SEEK_SET); /* move to the beginning of file */
//~ printf("FAILED!!!");
//~ }

//struct node* parent;
//parent = get_node_from_path(private_data,"/");
print_tree2((struct node*)private_data);
Expand Down
28 changes: 28 additions & 0 deletions src/rmdir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "../lib/rmdir.h"

int sifs_rmdir(const char* path) {
struct fuse_context* context;
context=fuse_get_context();

struct node* root;
root=(struct node*)context->private_data;
struct node *deleted = get_node_from_path(root, path);

struct node* parent = deleted->parent;
printf("#######%s########\n\n\n", parent->header->name);

int del_index;
for(int i = 0; i < parent->children_size; i++) {
if(!strcmp(parent->children[i]->header->name, deleted->header->name)){
del_index = i;
}
}

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

0 comments on commit 1715997

Please sign in to comment.