@@ -49,10 +49,8 @@ static auto set_lwt(const path &from_fn, const path &tsf) {
4949 fs::last_write_time (tsf, fs::last_write_time (from_fn));
5050}
5151
52- static bool should_patch (const path &fn, const path &hf, const path &hfn)
52+ static bool should_patch (patch_data_type &to_patch, const path &fn, const path &hf, const path &hfn)
5353{
54- static std::map<path, bool > to_patch;
55-
5654 auto tsf = path{ hf } += " .ts" s;
5755 ScopedFileLock fl (tsf);
5856
@@ -68,7 +66,7 @@ static bool should_patch(const path &fn, const path &hf, const path &hfn)
6866 return false ;
6967}
7068
71- void replaceInFileOnce (const path &fn, const String &from, const String &to, const path &lock_dir)
69+ void replaceInFileOnce (patch_data_type &to_patch, const path &fn, const String &from, const String &to, const path &lock_dir)
7270{
7371 auto hf = sha1 (to_string (normalize_path (fn)));
7472
@@ -78,16 +76,16 @@ void replaceInFileOnce(const path &fn, const String &from, const String &to, con
7876
7977 const auto lock = lock_dir / hf;
8078 auto tsf = path{ lock_dir / hf } += " .ts" s;
81- if (!should_patch (fn, lock, hfn))
79+ if (!should_patch (to_patch, fn, lock, hfn))
8280 return ;
8381
8482 ScopedFileLock fl (lock);
8583
8684 // double check
87- if (!should_patch (fn, lock, hfn))
85+ if (!should_patch (to_patch, fn, lock, hfn))
8886 return ;
8987
90- LOG_DEBUG (logger, std::format (" patching {} with patch file {} :\n from:\n {}\n to:\n {}" , fn.string (), hfn.string (), from, to));
88+ LOG_DEBUG (logger, std::format (" patching\n {} \n with patch file\n {} \n :\n from:\n {}\n to:\n {}\n " , fn.string (), hfn.string (), from, to));
9189
9290 auto s = read_file (fn);
9391 boost::replace_all (s, from, to);
@@ -96,7 +94,7 @@ void replaceInFileOnce(const path &fn, const String &from, const String &to, con
9694 set_lwt (fn, tsf);
9795}
9896
99- void pushFrontToFileOnce (const path &fn, const String &text, const path &lock_dir)
97+ void pushFrontToFileOnce (patch_data_type &to_patch, const path &fn, const String &text, const path &lock_dir)
10098{
10199 auto hf = sha1 (to_string (normalize_path (fn)));
102100
@@ -106,13 +104,13 @@ void pushFrontToFileOnce(const path &fn, const String &text, const path &lock_di
106104
107105 const auto lock = lock_dir / hf;
108106 auto tsf = path{ lock_dir / hf } += " .ts" s;
109- if (!should_patch (fn, lock, hfn))
107+ if (!should_patch (to_patch, fn, lock, hfn))
110108 return ;
111109
112110 ScopedFileLock fl (lock);
113111
114112 // double check
115- if (!should_patch (fn, lock, hfn))
113+ if (!should_patch (to_patch, fn, lock, hfn))
116114 return ;
117115
118116 LOG_DEBUG (logger, std::format (" pushFrontToFileOnce {} with patch file {}:\n {}" , fn.string (), hfn.string (), text));
@@ -124,7 +122,7 @@ void pushFrontToFileOnce(const path &fn, const String &text, const path &lock_di
124122 set_lwt (fn, tsf);
125123}
126124
127- void pushBackToFileOnce (const path &fn, const String &text, const path &lock_dir)
125+ void pushBackToFileOnce (patch_data_type &to_patch, const path &fn, const String &text, const path &lock_dir)
128126{
129127 auto hf = sha1 (to_string (normalize_path (fn)));
130128
@@ -134,13 +132,13 @@ void pushBackToFileOnce(const path &fn, const String &text, const path &lock_dir
134132
135133 const auto lock = lock_dir / hf;
136134 auto tsf = path{ lock_dir / hf } += " .ts" s;
137- if (!should_patch (fn, lock, hfn))
135+ if (!should_patch (to_patch, fn, lock, hfn))
138136 return ;
139137
140138 ScopedFileLock fl (lock);
141139
142140 // double check
143- if (!should_patch (fn, lock, hfn))
141+ if (!should_patch (to_patch, fn, lock, hfn))
144142 return ;
145143
146144 LOG_DEBUG (logger, std::format (" pushBackToFileOnce {} with patch file {}:\n {}" , fn.string (), hfn.string (), text));
0 commit comments