unison

Fork of Unison, a bi-directional file synchronization tool
git clone git://git.laack.co/unison.git
Log | Files | Refs | README | LICENSE

xferhint.ml (2311B)


      1 (* Unison file synchronizer: src/xferhint.ml *)
      2 (* Copyright 1999-2020, Benjamin C. Pierce
      3 
      4     This program is free software: you can redistribute it and/or modify
      5     it under the terms of the GNU General Public License as published by
      6     the Free Software Foundation, either version 3 of the License, or
      7     (at your option) any later version.
      8 
      9     This program is distributed in the hope that it will be useful,
     10     but WITHOUT ANY WARRANTY; without even the implied warranty of
     11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12     GNU General Public License for more details.
     13 
     14     You should have received a copy of the GNU General Public License
     15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16 *)
     17 
     18 
     19 let debug = Trace.debug "xferhint"
     20 
     21 let xferbycopying =
     22   Prefs.createBool "xferbycopying" true
     23     ~category:(`Advanced `Remote)
     24     "optimize transfers using local copies"
     25     ("When this preference is set, Unison will try to avoid transferring "
     26    ^ "file contents across the network by recognizing when a file with the "
     27    ^ "required contents already exists in the target replica.  This usually "
     28    ^ "allows file moves to be propagated very quickly.  The default value is "
     29    ^ "\\texttt{true}.  ")
     30 
     31 module FPMap =
     32   Hashtbl.Make
     33     (struct
     34        type t = Os.fullfingerprint
     35        let hash = Os.fullfingerprintHash
     36        let equal = Os.fullfingerprintEqual
     37      end)
     38 
     39 type handle = Os.fullfingerprint
     40 
     41 (* map(fingerprint, path) *)
     42 let fingerprint2pathMap = FPMap.create 10000
     43 
     44 let deleteEntry fp =
     45   debug (fun () ->
     46     Util.msg "deleteEntry: fp=%s\n" (Os.fullfingerprint_to_string fp));
     47   FPMap.remove fingerprint2pathMap fp
     48 
     49 let lookup fp =
     50   assert (Prefs.read xferbycopying);
     51   debug (fun () ->
     52     Util.msg "lookup: fp = %s\n" (Os.fullfingerprint_to_string fp));
     53   try
     54     let (fspath, path) = FPMap.find fingerprint2pathMap fp in
     55     Some (fspath, path, fp)
     56   with Not_found ->
     57     None
     58 
     59 let insertEntry fspath path fp =
     60   if Prefs.read xferbycopying && not (Os.isPseudoFingerprint fp) then begin
     61     debug (fun () ->
     62       Util.msg "insertEntry: fspath=%s, path=%s, fp=%s\n"
     63         (Fspath.toDebugString fspath)
     64         (Path.toString path) (Os.fullfingerprint_to_string fp));
     65     FPMap.replace fingerprint2pathMap fp (fspath, path)
     66   end