Skip to content

Commit

Permalink
Merge pull request #131 from jorge-lip/bugfix-removetemp
Browse files Browse the repository at this point in the history
fix tmp cleanup on non ext fs
  • Loading branch information
jopasserat committed Jan 11, 2018
2 parents 0bf2ee1 + d189b53 commit ca57ca5
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/path/temp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ const char *get_temp_directory()
return temp_directory;
}

/**
* Handle the return of d_type = DT_UNKNOWN by readdir(3)
* Not all filesystems support returning d_type in readdir(3)
*/
static int get_dtype(struct dirent *de)
{
int dtype = de ? de->d_type : DT_UNKNOWN;
struct stat st;

if (dtype != DT_UNKNOWN)
return dtype;
if (lstat(de->d_name, &st))
return dtype;
if (S_ISREG(st.st_mode))
return DT_REG;
if (S_ISDIR(st.st_mode))
return DT_DIR;
if (S_ISLNK(st.st_mode))
return DT_LNK;
return dtype;
}

/**
* Remove recursively the content of the current working directory.
* This latter has to lie in temp_directory (ie. "/tmp" on most
Expand Down Expand Up @@ -117,7 +139,7 @@ static int clean_temp_cwd()
continue;
}

if (entry->d_type == DT_DIR) {
if (get_dtype(entry) == DT_DIR) {
status = chdir(entry->d_name);
if (status < 0) {
note(NULL, WARNING, SYSTEM, "can't chdir '%s'", entry->d_name);
Expand Down

1 comment on commit ca57ca5

@oxr463
Copy link
Collaborator

@oxr463 oxr463 commented on ca57ca5 Dec 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.