Skip to content

Commit

Permalink
Trivial safeguard in Force_Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Aug 5, 2023
1 parent 9b476d0 commit 0d18391
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/alire/alire-directories.adb
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,17 @@ package body Alire.Directories is
-- Force_Delete --
------------------

procedure Force_Delete (Path : Any_Path) is
procedure Force_Delete (Path : Absolute_Path) is
use Ada.Directories;
begin

-- Given that we never delete anything outside one of our folders, the
-- conservatively shortest thing we can be asked to delete is something
-- like "/c/alire". This is for peace of mind.
if Path'Length < 8 then
Recoverable_Error ("Suspicious deletion request for path: " & Path);
end if;

if Exists (Path) then
if Kind (Path) = Ordinary_File then
Trace.Debug ("Deleting file " & Path & "...");
Expand Down
4 changes: 2 additions & 2 deletions src/alire/alire-directories.ads
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ package Alire.Directories is
-- In Windows, git checkouts are created with read-only file that do not
-- sit well with Ada.Directories.Delete_Tree.

procedure Force_Delete (Path : Any_Path);
procedure Force_Delete (Path : Absolute_Path);
-- Calls Ensure_Deletable and then uses GNATCOLL.VFS deletion

procedure Delete_Tree (Path : Any_Path) renames Force_Delete;
procedure Delete_Tree (Path : Absolute_Path) renames Force_Delete;
-- Delete Path, and anythin below if it was a dir

function Find_Files_Under (Folder : String;
Expand Down
4 changes: 2 additions & 2 deletions src/alr/alr-commands-clean.adb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ package body Alr.Commands.Clean is
-- Delete --
------------

procedure Delete (Path : String)
procedure Delete (Path : Alire.Absolute_Path)
is
use type Ada.Directories.File_Size;
begin
Expand Down Expand Up @@ -59,7 +59,7 @@ package body Alr.Commands.Clean is
-- Current workspace

Alire.Directories.Traverse_Tree
(Start => ".",
(Start => Alire.Directories.Current,
Doing => Add_Target'Access,
Recurse => True);

Expand Down

0 comments on commit 0d18391

Please sign in to comment.