Skip to content

Commit

Permalink
replaced rename with a new file
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksArt000 committed Jul 23, 2024
1 parent d00dce8 commit be980f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Binary file modified cutils.a
Binary file not shown.
26 changes: 20 additions & 6 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,25 @@ int mvsp(char* old_path,char* new_path)
return mvlink(old_path,new_path);
}

if (rename(old_path,new_path) != 0) {
msg(ERROR,"Error moving file\n");
return -1;
}

return 0;
struct stat st;
stat(old_path, &st);
int size = st.st_size;

char* buffer = malloc(size);

FILE *old_ptr;
FILE *new_ptr;

old_ptr = fopen(old_path,"r");
fread(buffer, sizeof(char), size, old_ptr);
fclose(old_ptr);

new_ptr = fopen(new_path,"w");
fwrite(buffer, sizeof(char), size, new_ptr);
int result = fclose(new_ptr);

chown(new_path, getuid(), getgid());
chmod(new_path, 0755);
return result;
}

0 comments on commit be980f8

Please sign in to comment.