Skip to content

Commit 0bee292

Browse files
V704-034: Limit number of logs in $ALS_HOME/.als
Add logThreshold property to limit the number of logs.
1 parent 9bde2dc commit 0bee292

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

source/ada/lsp-ada_driver.adb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ procedure LSP.Ada_Driver is
175175
(VSS.Standard_Paths.Home_Location)
176176
else ALS_Home)));
177177
ALS_Dir : constant Virtual_File := Home_Dir / ".als";
178+
Clean_ALS_Dir : Boolean := False;
178179
GNATdebug : constant Virtual_File := Create_From_Base
179180
(".gnatdebug");
180181

@@ -248,6 +249,8 @@ begin
248249
Parse_Config_File (GNATdebug);
249250

250251
elsif ALS_Dir.Is_Directory then
252+
Clean_ALS_Dir := True;
253+
251254
-- Search for custom traces config in traces.cfg
252255
Parse_Config_File (+Virtual_File'(ALS_Dir / "traces.cfg").Full_Name);
253256

@@ -346,6 +349,9 @@ begin
346349
end if;
347350

348351
Server.Finalize;
352+
if Clean_ALS_Dir then
353+
Ada_Handler.Clean_Logs (ALS_Dir);
354+
end if;
349355
Ada_Handler.Cleanup;
350356

351357
-- Clean secondary stack up

source/ada/lsp-ada_handlers.adb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,30 @@ package body LSP.Ada_Handlers is
531531
LSP.File_Monitors.Unchecked_Free (Self.File_Monitor);
532532
end Cleanup;
533533

534+
----------------
535+
-- Clean_Logs --
536+
----------------
537+
538+
procedure Clean_Logs (Self : access Message_Handler; Dir : Virtual_File) is
539+
Files : File_Array_Access := Read_Dir (Dir, Files_Only);
540+
Dummy : Boolean;
541+
Cpt : Integer := 0;
542+
begin
543+
Sort (Files.all);
544+
-- Browse the log files in reverse timestamp order
545+
for F of reverse Files.all loop
546+
-- Filter out files like traces.cfg
547+
if GNATCOLL.Utils.Ends_With (+F.Base_Name, ".log") then
548+
Cpt := Cpt + 1;
549+
-- Delete the old logs
550+
if Cpt > Self.Log_Threshold then
551+
Delete (F, Dummy);
552+
end if;
553+
end if;
554+
end loop;
555+
Unchecked_Free (Files);
556+
end Clean_Logs;
557+
534558
-----------------------
535559
-- Exit_Notification --
536560
-----------------------
@@ -4092,6 +4116,8 @@ package body LSP.Ada_Handlers is
40924116
"documentationStyle";
40934117
useCompletionSnippets : constant String :=
40944118
"useCompletionSnippets";
4119+
logThreshold : constant String :=
4120+
"logThreshold";
40954121

40964122
Ada : constant LSP.Types.LSP_Any := Value.settings.Get ("ada");
40974123
File : VSS.Strings.Virtual_String;
@@ -4170,6 +4196,10 @@ package body LSP.Ada_Handlers is
41704196
Self.Named_Notation_Threshold := Ada.Get (namedNotationThreshold);
41714197
end if;
41724198

4199+
if Ada.Has_Field (logThreshold) then
4200+
Self.Log_Threshold := Ada.Get (logThreshold);
4201+
end if;
4202+
41734203
-- Check the 'useCompletionSnippets' flag to see if we should use
41744204
-- snippets in completion (if the client supports it).
41754205
if not Self.Completion_Snippets_Enabled then

source/ada/lsp-ada_handlers.ads

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ package LSP.Ada_Handlers is
6464
procedure Cleanup (Self : access Message_Handler);
6565
-- Free memory referenced by Self
6666

67+
procedure Clean_Logs (Self : access Message_Handler; Dir : Virtual_File);
68+
-- Remove the oldest logs in Dir
69+
6770
subtype Context_Access is LSP.Ada_Context_Sets.Context_Access;
6871

6972
function From_File
@@ -332,6 +335,10 @@ private
332335
File_Monitor : LSP.File_Monitors.File_Monitor_Access;
333336
-- Filesystem monitoring
334337

338+
Log_Threshold : Natural := 10;
339+
-- Maximum number of logs (should be > to the number of servers run
340+
-- simultaneously)
341+
335342
---------------------------------------
336343
-- Experimental Client Capabilities --
337344
---------------------------------------

0 commit comments

Comments
 (0)