Skip to content

Commit 0239acf

Browse files
committed
Delete files even when stat fails
Delete files even when a stat() call on the file, due to broken links etc, fails. Without this change the symbolic links to ADIOS BP files are not deleted.
1 parent 6b6b24a commit 0239acf

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/clib/pio_file.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,18 +1185,22 @@ int PIOc_deletefile_impl(int iosysid, const char *filename)
11851185
{
11861186
spio_remove_directory(adios_bp_filename);
11871187
}
1188+
11881189
free(adios_bp_filename);
11891190
#endif
11901191

1191-
if(stat(filename, &sd) == 0){
1192-
if(S_ISDIR(sd.st_mode)){
1192+
int ret = stat(filename, &sd);
1193+
if ((ret == 0) && S_ISDIR(sd.st_mode))
1194+
{
11931195
/* Delete the directory pointed to by filename (e.g. NCZarr files) */
11941196
spio_remove_directory(filename);
1195-
}
1196-
else{
1197-
/* Delete the file (for ADIOS BP files, delete the symlink file) */
1197+
}
1198+
else
1199+
{
1200+
/* Delete the file (for ADIOS BP files, delete the symlink file).
1201+
Ignore stat errors (dangling symlinks etc) and force unlink
1202+
*/
11981203
ierr = unlink(filename);
1199-
}
12001204
}
12011205
}
12021206

0 commit comments

Comments
 (0)