Skip to content

Commit

Permalink
[sqlite] remove symlink after use
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ngorogiannis authored and facebook-github-bot committed Nov 26, 2024
1 parent 87b0960 commit 3cef794
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions infer/src/base/SqliteUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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


Expand Down

0 comments on commit 3cef794

Please sign in to comment.