1--
2--  Copyright (c) 2014-15 John Marino <draco@marino.st>
3--
4--  Permission to use, copy, modify, and distribute this software for any
5--  purpose with or without fee is hereby granted, provided that the above
6--  copyright notice and this permission notice appear in all copies.
7--
8--  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9--  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10--  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11--  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12--  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13--  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14--  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15--
16
17
18with DragonFly.HAMMER.Binding;
19with Ada.Containers.Indefinite_Vectors;
20with Ada.Containers.Vectors;
21with Ada.Directories;
22
23package DragonFly.HAMMER.Ghosts is
24
25   package HB  renames DragonFly.HAMMER.Binding;
26   package DIR renames Ada.Directories;
27
28   package Filename_Container is
29      new Ada.Containers.Indefinite_Vectors (Positive, String);
30
31   package TID_Container is
32      new Ada.Containers.Vectors (Positive, HB.hammer_tid);
33
34   package SortEntry is new Filename_Container.Generic_Sorting;
35   package SortTid   is new TID_Container.Generic_Sorting;
36
37   procedure scan_for_file_ghosts (
38      directory_path   : in String;
39      file_ghosts      : out Filename_Container.Vector;
40      directory_ghosts : out Filename_Container.Vector);
41   --  Given an existing directory path, the procedure will produce
42   --  both a list of deleted directories and a list of files deleted
43   --  (but with available version) from that directory
44
45
46private
47
48   living_files : Filename_Container.Vector;
49   living_dirs  : Filename_Container.Vector;
50
51   procedure establish_baseline (directory_path : in String);
52   --  Get current listing of ordinary files and directories
53
54   function format_as_hex (bignum : HB.hammer_tid) return String;
55   --  Format string with c-equivalent of %016x
56
57   procedure scan_history_of_directory (
58      fd             : in file_descriptor;
59      directory_path : in String;
60      ghosts_file    : in out Filename_Container.Vector;
61      ghosts_dir     : in out Filename_Container.Vector);
62   --  Look at a specific version of a directory, filtered by type, and
63   --  determine which files have never been seen before (previously deleted)
64
65   procedure scan_transaction (
66      directory_path : in String;
67      transaction    : in String;
68      fkind          : in DIR.File_Kind;
69      ghost          : in out Filename_Container.Vector);
70   --  Scan historical version of directory for either deleted files or
71   --  directories, and augment "ghost" container as necessary.
72
73   function directory_has_files (directory_path : String) return Boolean;
74   --  if the directory has at least one entry other than "." or "..", this
75   --  function will return true.  If the path doesn't exist, it will return
76   --  false, so it can check this too.
77
78end DragonFly.HAMMER.Ghosts;
79