Sophie

Sophie

distrib > Mandriva > 2009.1 > i586 > media > main-release-src > by-pkgid > 53a485d7275ab3ce9c82a9b56c679e42 > files > 7

minicom-2.3-6mdv2009.1.src.rpm

--- src/file.c	2008-12-21 21:37:46.000000000 +0100
+++ src/file.c.oden	2008-12-21 21:38:24.000000000 +0100
@@ -282,6 +282,8 @@ static int new_filedir(GETSDIR_ENTRY *o_
   int initial_y = (76 - (WHAT_NR_OPTIONS * WHAT_WIDTH >= 76
                    ? 74 : WHAT_NR_OPTIONS * WHAT_WIDTH)) / 2;
   size_t i;
+  int rval;
+  char * new_prev_dir;
 
   cur      =  0;
   ocur     =  0;
@@ -295,11 +297,6 @@ static int new_filedir(GETSDIR_ENTRY *o_
   dprev    = -1;
   tag_cnt  =  0;
 
-  /* got to do some error-checking here!!!  Maybe use mcd(), too! */
-  if (prev_dir != NULL)
-    free(prev_dir);
-  prev_dir = getcwd(NULL, BUFSIZ);
-
   /*
    * get last directory
    */
@@ -329,7 +326,30 @@ static int new_filedir(GETSDIR_ENTRY *o_
   if (strlen(work_dir) > 1 && work_dir[strlen(work_dir) - 1] == '/')
     work_dir[strlen(work_dir) - 1] = (char)0;
 
-  chdir(work_dir);
+  /* get the current working directory, which will become the prev_dir, on success */
+  new_prev_dir = getcwd(NULL, BUFSIZ);
+  if (new_prev_dir == NULL) {
+    return -1;
+  } 
+
+  rval = chdir(work_dir);
+  if (rval == 0) {
+    /* was able to change to new working directory */
+    free(prev_dir);
+    prev_dir = new_prev_dir;
+  }
+  else {
+    /* Could not change to the new working directory */
+    mc_wbell();
+    werror(
+        _("Could not change to directory %s (%s)"), 
+        work_dir,
+        strerror(errno));
+
+    /* restore the previous working directory */
+    free(work_dir);
+    work_dir = set_work_dir(new_prev_dir, strlen(new_prev_dir));
+  }
 
   /* All right, draw the file directory! */
 
@@ -435,7 +455,7 @@ static int new_filedir(GETSDIR_ENTRY *o_
     mc_wredraw(dsub, 1);
   }
 
-  return 0;
+  return rval;
 }