- if (entry->d_type == DT_REG) {
- unlinkat(dirfd(trace_dir), entry->d_name, 0);
+ struct stat st;
+ char filename[PATH_MAX];
+
+ if (snprintf(filename, sizeof(filename), "%s/%s",
+ trace_path, entry->d_name) <= 0) {
+ continue;
+ }
+
+ if (stat(entry->d_name, &st)) {
+ continue;
+ }
+
+ if (S_ISREG(st.st_mode)) {
+ unlinkat(bt_dirfd(trace_dir), entry->d_name, 0);