@@ -149,6 +149,24 @@ public:
149149 }
150150 }
151151
152+ static void removeFile (char *path) {
153+ // Get the status so we can determine if it's a file or directory. If we
154+ // can't stat the file, ignore it.
155+ struct stat buf;
156+ if (stat (path, &buf) != 0 )
157+ return ;
158+
159+ // If this is not a regular file, ignore it. We want to prevent removal
160+ // of special files like /dev/null, even if the compiler is being run
161+ // with the super-user permissions.
162+ if (!S_ISREG (buf.st_mode ))
163+ return ;
164+
165+ // Otherwise, remove the file. We ignore any errors here as there is
166+ // nothing else we can do.
167+ unlink (path);
168+ }
169+
152170 // Signal-safe.
153171 static void removeAllFiles (std::atomic<FileToRemoveList *> &Head) {
154172 // If cleanup were to occur while we're removing files we'd have a bad time.
@@ -162,21 +180,7 @@ public:
162180 // If erasing was occuring while we're trying to remove files we'd look
163181 // at free'd data. Take away the path and put it back when done.
164182 if (char *path = currentFile->Filename .exchange (nullptr )) {
165- // Get the status so we can determine if it's a file or directory. If we
166- // can't stat the file, ignore it.
167- struct stat buf;
168- if (stat (path, &buf) != 0 )
169- continue ;
170-
171- // If this is not a regular file, ignore it. We want to prevent removal
172- // of special files like /dev/null, even if the compiler is being run
173- // with the super-user permissions.
174- if (!S_ISREG (buf.st_mode ))
175- continue ;
176-
177- // Otherwise, remove the file. We ignore any errors here as there is
178- // nothing else we can do.
179- unlink (path);
183+ removeFile (path);
180184
181185 // We're done removing the file, erasing can safely proceed.
182186 currentFile->Filename .exchange (path);
0 commit comments