improvenment of path handling
This commit is contained in:
12
backend.c
12
backend.c
@ -39,6 +39,7 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
scandir(path, &entry, skip_hidden_files, alphasort);
|
scandir(path, &entry, skip_hidden_files, alphasort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
for (i = 0; i < *dir_file_count; i++ ) {
|
for (i = 0; i < *dir_file_count; i++ ) {
|
||||||
@ -51,7 +52,16 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
struct stat *file;
|
struct stat *file;
|
||||||
file = malloc(sizeof(struct stat));
|
file = malloc(sizeof(struct stat));
|
||||||
memset(file, ' ', sizeof(struct stat));
|
memset(file, ' ', sizeof(struct stat));
|
||||||
lstat(dir_content[i].file_name, file);
|
|
||||||
|
/* using the full path allows using the same function for all windows */
|
||||||
|
unsigned long path_len = strlen(path);
|
||||||
|
char *full_path = malloc(strlen(path) + strlen(entry[i]->d_name) + 1 + sizeof("/"));
|
||||||
|
memcpy(full_path, path, strlen(path));
|
||||||
|
memcpy(full_path + path_len, "/", sizeof("/"));
|
||||||
|
memcpy(full_path + path_len + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
|
||||||
|
|
||||||
|
lstat(full_path, file);
|
||||||
|
free(full_path);
|
||||||
|
|
||||||
if (S_ISDIR(file->st_mode)) {
|
if (S_ISDIR(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_DIR;
|
dir_content[i].file_type = FILE_TYPE_DIR;
|
||||||
|
14
threading.c
14
threading.c
@ -58,6 +58,7 @@ void *thread_lft(void *data){
|
|||||||
|
|
||||||
free(lft_content);
|
free(lft_content);
|
||||||
|
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
if((path=getcwd(NULL, 0)) == NULL) {
|
if((path=getcwd(NULL, 0)) == NULL) {
|
||||||
lft_content = malloc(sizeof(file));
|
lft_content = malloc(sizeof(file));
|
||||||
@ -66,18 +67,13 @@ void *thread_lft(void *data){
|
|||||||
lft_file_count = 1;
|
lft_file_count = 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
char *parent ;
|
path[strrchr(path, '/')-path] = '\0';
|
||||||
if((parent = malloc(strlen(path)+strlen("/..")+1)) != NULL){
|
path[0] = '/';
|
||||||
parent[0] = '\0'; /* ensures empty string */
|
|
||||||
strcat(parent, path);
|
|
||||||
strcat(parent, "/..");
|
|
||||||
}
|
|
||||||
|
|
||||||
lft_file_count = (unsigned long)get_dir_size(parent);
|
lft_file_count = (unsigned long)get_dir_size(path);
|
||||||
lft_content = malloc(lft_file_count * sizeof(file));
|
lft_content = malloc(lft_file_count * sizeof(file));
|
||||||
memset(lft_content, ' ', lft_file_count * sizeof(file));
|
memset(lft_content, ' ', lft_file_count * sizeof(file));
|
||||||
get_dir_content(parent, &lft_file_count, lft_content);
|
get_dir_content(path, &lft_file_count, lft_content);
|
||||||
free(parent);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
|
Reference in New Issue
Block a user