@@ -43,8 +43,11 @@ namespace app {
43
43
}
44
44
45
45
m_pool.queueJob ([path = std::move (path), this ] {
46
+ if (m_shouldStop) return ;
47
+
46
48
if (!processFile (path)) {
47
49
m_promise.set_value (false );
50
+ m_shouldStop = true ;
48
51
return ;
49
52
}
50
53
@@ -90,11 +93,17 @@ namespace app {
90
93
const auto & output = m_info.outputDir / fs::relative (dirpath, m_info.inputDir );
91
94
VERBOSE (" Creating directory in '{}'..." , output.string ());
92
95
std::error_code e;
93
- fs::create_directories (output, e);
96
+ if (!fs::create_directory (output, e)) {
97
+ if (e) {
98
+ ERROR (" Failed to create directory in '{}'" , output.string ());
99
+ return false ;
100
+ }
94
101
95
- if (e) {
96
- ERROR (" Failed to create directory in '{}'" , output.string ());
97
- return false ;
102
+ WARNING (" Directory located in '{}' already exists" , output.string ());
103
+ } else {
104
+ std::unique_lock lock (m_mtx);
105
+ m_cachefile.writePath (output);
106
+ m_cachefile.flush ();
98
107
}
99
108
100
109
return true ;
@@ -125,9 +134,9 @@ namespace app {
125
134
m_cachefile{cachepath} {
126
135
char buf[6 ];
127
136
m_cachefile.read (buf, 6 );
128
- if (strcmp (buf, Package::MAGIC_NUMBER) != 0 ) {
137
+ if (strncmp (buf, Package::MAGIC_NUMBER, sizeof (buf) ) != 0 ) {
129
138
WARNING (" File '{}' isn't a cache" , m_cachefile.filepath ().string ());
130
- return ;
139
+ return ;
131
140
}
132
141
133
142
unsigned flags;
@@ -160,15 +169,24 @@ namespace app {
160
169
}
161
170
162
171
bool UninstallPackage::processDirectory (const fs::path& dirpath) {
163
- // Nothing to do
172
+ m_disposeDirs. push (dirpath);
164
173
return true ;
165
174
}
166
175
167
176
void UninstallPackage::onEndProcess () {
168
177
auto f = m_cachefile.filepath ();
169
178
m_cachefile.close ();
170
179
171
- fs::remove_all (m_info.outputDir );
180
+ for (fs::path p; !m_disposeDirs.empty (); m_disposeDirs.pop ()) {
181
+ p = m_disposeDirs.top ();
182
+ VERBOSE (" Deleting directory located in '{}'" , p.string ());
183
+ if (std::error_code e; fs::remove (p, e), e) {
184
+ WARNING (" Failed to delete directory '{}': {}" , p.string (), e.message ());
185
+ }
186
+ }
187
+
188
+ if (std::error_code e; !fs::remove (m_info.outputDir , e))
189
+ WARNING (" Directory '{}' isn't empty" , m_info.outputDir .string ());
172
190
fs::remove (f);
173
191
}
174
192
} // namespace app
0 commit comments