summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-04-26 10:54:14 +0200
committerYorhel <git@yorhel.nl>2009-04-26 10:54:14 +0200
commit4b6456d0b97610c381ec0369897e3c68d7a98113 (patch)
treef18e231594b3260fbac13cf56e1815e32b0a8a53
parentf6e34e520eda903760d38366b8941a879e8de830 (diff)
Improved deletion performance
-rw-r--r--src/delete.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/delete.c b/src/delete.c
index cfd51bf..5e54d53 100644
--- a/src/delete.c
+++ b/src/delete.c
@@ -167,11 +167,6 @@ int delete_key(int ch) {
int delete_dir(struct dir *dr) {
struct dir *nxt, *cur;
int r;
- char *path;
-
- /* calling path_chdir() this often isn't exactly efficient... */
- path = getpath(dr->parent);
- path_chdir(path);
/* check for input or screen resizes */
curdir = dr;
@@ -180,6 +175,8 @@ int delete_dir(struct dir *dr) {
/* do the actual deleting */
if(dr->flags & FF_DIR) {
+ if((r = chdir(dr->name)) < 0)
+ goto delete_nxt;
if(dr->sub != NULL) {
nxt = dr->sub;
while(nxt != NULL) {
@@ -189,10 +186,13 @@ int delete_dir(struct dir *dr) {
return 1;
}
}
+ if((r = chdir("..")) < 0)
+ goto delete_nxt;
r = rmdir(dr->name);
} else
r = unlink(dr->name);
+delete_nxt:
/* error occured, ask user what to do */
if(r == -1 && !ignoreerr) {
state = DS_FAILED;
@@ -217,8 +217,18 @@ void delete_process() {
if(input_handle(0))
return browse_init(root);
+ /* chdir */
+ if(path_chdir(getpath(root->parent)) < 0) {
+ state = DS_FAILED;
+ lasterrno = errno;
+ while(state == DS_FAILED)
+ if(input_handle(0))
+ return;
+ }
+
/* delete */
seloption = 0;
+ state = DS_PROGRESS;
if(delete_dir(root))
browse_init(root);
else {
@@ -231,7 +241,7 @@ void delete_process() {
void delete_init(struct dir *dr, struct dir *s) {
state = DS_CONFIRM;
- root = dr;
+ root = curdir = dr;
pstate = ST_DEL;
nextsel = s;
}