Skip to content

Commit

Permalink
semplified some code, updated some doc
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeDP committed Jul 9, 2015
1 parent ac249cb commit a29be4a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* TODO:
* fm_functions doc
* Update doc
* semplify code
*/
10 changes: 1 addition & 9 deletions src/fm_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ static int recursive_copy(const char *path, const struct stat *sb, int typeflag,
}
close(fd_to);
close(fd_from);
flock(fd_to, LOCK_UN);
flock(fd_from, LOCK_UN);
}
}
return 0;
Expand Down Expand Up @@ -362,13 +360,7 @@ void rename_file_folders(void)

static int recursive_remove(const char *path, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
int res, fd;

fd = open(path, O_RDONLY);
flock(fd, LOCK_EX);
res = remove(path);
close(fd);
return res;
return remove(path);
}

static int rmrf(const char *path)
Expand Down
12 changes: 7 additions & 5 deletions src/helper_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ static thread_job_list *add_thread(thread_job_list *h, int type, const char *pat
}

/*
* running_h is a ptr to the currently running job.
* This function will free its memory and set it to NULL.
* This function will move thread_job_list head to head->next, and will free old head memory and set it to NULL.
*/
void free_running_h(void)
{
Expand Down Expand Up @@ -200,6 +199,9 @@ static void init_thread_helper(const char *temp, const char *str)
}
}

/*
* Helper function that will copy file_list *selected to current_th->selected_files, then will free selected.
*/
static void copy_selected_files(void)
{
file_list *tmp = selected;
Expand All @@ -213,16 +215,16 @@ static void copy_selected_files(void)
}

/*
* - first check if we come from a recursive call (if we're in a running th), then frees previously finished job and print its completion mesg.
* - if thread_h is not NULL, and thread_f is already assigned, the th has another job waiting for it, so we run it, else we finished our work: num_of_jobs = 0.
* First check if we come from a recursive call, then frees previously finished job and print its completion mesg.
* If thread_h is not NULL, the th has another job waiting for it, so we run it, else we finished our work: num_of_jobs = 0.
*/
static void *execute_thread(void *x)
{
if (x) {
free_running_h();
print_info(thread_m.str, thread_m.line);
}
if (thread_h && thread_h->f) {
if (thread_h) {
thread_h->f();
return execute_thread(thread_h);
} else {
Expand Down
13 changes: 5 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ static void main_loop(void)

while (!quit) {
c = wgetch(ps[active].fm);
pthread_mutex_lock(&lock);
stat(ps[active].nl[ps[active].curr_pos], &current_file_stat);
pthread_mutex_unlock(&lock);
if ((c >= 'A') && (c <= 'Z')) {
c = tolower(c);
}
Expand All @@ -180,9 +183,6 @@ static void main_loop(void)
switch_hidden();
break;
case 10: // enter to change dir or open a file.
pthread_mutex_lock(&lock);
stat(ps[active].nl[ps[active].curr_pos], &current_file_stat);
pthread_mutex_unlock(&lock);
if (S_ISDIR(current_file_stat.st_mode) || S_ISLNK(current_file_stat.st_mode)) {
change_dir(ps[active].nl[ps[active].curr_pos]);
} else {
Expand All @@ -205,7 +205,7 @@ static void main_loop(void)
init_thread(NEW_FILE_TH, new_file, ps[active].my_cwd);
break;
case 'r': //remove file
if (strcmp(strrchr(ps[active].nl[ps[active].curr_pos], '/') + 1, "..") != 0) {
if (strcmp(strrchr(ps[active].nl[ps[active].curr_pos], '/') + 1, "..") != 0) { // check this is not ".." dir
ask_user(sure, &x, 1, 'n');
if (x == 'y') {
init_thread(RM_TH, remove_file, ps[active].nl[ps[active].curr_pos]);
Expand All @@ -222,7 +222,7 @@ static void main_loop(void)
init_thread(PASTE_TH, paste_file, ps[active].my_cwd);
}
break;
case 'l':
case 'l': // show helper mess
trigger_show_helper_message();
break;
case 's': // show stat about files (size and perms)
Expand Down Expand Up @@ -250,9 +250,6 @@ static void main_loop(void)
break;
#ifdef LIBCUPS_PRESENT
case 'p': // p to print
pthread_mutex_lock(&lock);
stat(ps[active].nl[ps[active].curr_pos], &current_file_stat);
pthread_mutex_unlock(&lock);
if (S_ISREG(current_file_stat.st_mode) && !get_mimetype(ps[active].nl[ps[active].curr_pos], "x-executable")) {
print_support(ps[active].nl[ps[active].curr_pos]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ void print_info(const char *str, int i)
wclrtoeol(info_win);
}
k = 0;
if (thread_h && thread_h->type) {
if (thread_h) {
sprintf(st, "[%d/%d] %s", thread_h->num, num_of_jobs, thread_job_mesg[thread_h->type - 1]);
k = strlen(st) + 1;
mvwprintw(info_win, INFO_LINE, COLS - strlen(st), st);
Expand Down

0 comments on commit a29be4a

Please sign in to comment.