summaryrefslogtreecommitdiff
path: root/gcc/ada/g-dirope.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2007-09-26 10:44:16 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2007-09-26 10:44:16 +0000
commite41e0253937dc242a0a4324c880e1e8a7b57738e (patch)
treea9b7b5e8ada88d38fc353bedb861d9539ba2c732 /gcc/ada/g-dirope.adb
parent09c6615b21f5e393e43f598f50e184bd063638a7 (diff)
downloadgcc-e41e0253937dc242a0a4324c880e1e8a7b57738e.tar.gz
2007-09-26 Florian Villoing <villoing@adacore.com>
* g-dirope.adb (Remove_Dir): In case we are removing directories recursively, make sure that if an exception is raised during the processing, the current working directory is reset to its initial value before propagating the exception. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@128792 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/g-dirope.adb')
-rw-r--r--gcc/ada/g-dirope.adb60
1 files changed, 40 insertions, 20 deletions
diff --git a/gcc/ada/g-dirope.adb b/gcc/ada/g-dirope.adb
index bb8ff93fb20..fe9b5f17aa6 100644
--- a/gcc/ada/g-dirope.adb
+++ b/gcc/ada/g-dirope.adb
@@ -743,32 +743,52 @@ package body GNAT.Directory_Operations is
-- Remove directory and all files and directories that it may contain
else
- Change_Dir (Dir_Name);
- Open (Working_Dir, ".");
+ -- Substantial comments needed. See RH for revision 1.50 ???
- loop
- Read (Working_Dir, Str, Last);
- exit when Last = 0;
+ begin
+ Change_Dir (Dir_Name);
+ Open (Working_Dir, ".");
- if GNAT.OS_Lib.Is_Directory (Str (1 .. Last)) then
- if Str (1 .. Last) /= "." and then Str (1 .. Last) /= ".." then
- Remove_Dir (Str (1 .. Last), True);
- Remove_Dir (Str (1 .. Last));
- end if;
+ loop
+ Read (Working_Dir, Str, Last);
+ exit when Last = 0;
- else
- GNAT.OS_Lib.Delete_File (Str (1 .. Last), Success);
+ if GNAT.OS_Lib.Is_Directory (Str (1 .. Last)) then
+ if Str (1 .. Last) /= "."
+ and then
+ Str (1 .. Last) /= ".."
+ then
+ Remove_Dir (Str (1 .. Last), True);
+ Remove_Dir (Str (1 .. Last));
+ end if;
+
+ else
+ GNAT.OS_Lib.Delete_File (Str (1 .. Last), Success);
- if not Success then
- Change_Dir (Current_Dir);
- raise Directory_Error;
+ if not Success then
+ Change_Dir (Current_Dir);
+ raise Directory_Error;
+ end if;
end if;
- end if;
- end loop;
+ end loop;
+
+ Change_Dir (Current_Dir);
+ Close (Working_Dir);
+ Remove_Dir (Dir_Name);
+
+ exception
+ when others =>
- Change_Dir (Current_Dir);
- Close (Working_Dir);
- Remove_Dir (Dir_Name);
+ -- An exception occurred. We must make sure the current working
+ -- directory is unchanged.
+
+ Change_Dir (Current_Dir);
+
+ -- What if the Change_Dir raises an exception itself, shouldn't
+ -- that be protected? ???
+
+ raise;
+ end;
end if;
end Remove_Dir;