From 3cef794b280b1ddc3a58911bd80cd28f61d583e3 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Tue, 26 Nov 2024 02:55:58 -0800 Subject: [PATCH] [sqlite] remove symlink after use Summary: Be a good citizen and remove the temporary symlink created during database attachment after use. Reviewed By: geralt-encore Differential Revision: D66490926 Privacy Context Container: L1208441 fbshipit-source-id: 3e31723af1dc662beff5460ee81bd5072e4281ff --- infer/src/base/SqliteUtils.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/infer/src/base/SqliteUtils.ml b/infer/src/base/SqliteUtils.ml index aea2cc934b..f62809801a 100644 --- a/infer/src/base/SqliteUtils.ml +++ b/infer/src/base/SqliteUtils.ml @@ -95,16 +95,16 @@ let db_close db = let sqlite_max_path_length = 500 let with_attached_db ~db_file ~db_name ?(immutable = false) ~f db = - let db_file = + let db_file, remove_after_use = if (* If [db_file]'s length exceeds Sqlite's limit then use a symlink trampoline. Do not bother if [db_file] is a special Sqlite path like [:memory:] *) String.length db_file < sqlite_max_path_length || String.is_prefix db_file ~prefix:":" - then db_file + then (db_file, false) else let link_name = Filename.temp_file "infer-merge-sqlite-trampoline" "db" in Unix.symlink ~target:db_file ~link_name ; - link_name + (link_name, true) in let attach_stmt = Printf.sprintf "ATTACH '%s%s%s' AS %s" @@ -117,6 +117,7 @@ let with_attached_db ~db_file ~db_name ?(immutable = false) ~f db = exec db ~stmt:attach_stmt ~log:(Printf.sprintf "attaching database '%s'" db_file) ; let result = f () in exec db ~stmt:("DETACH " ^ db_name) ~log:(Printf.sprintf "detaching database '%s'" db_file) ; + if remove_after_use then Unix.unlink db_file ; result