Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tmp cleanup on non ext fs #131

Merged
merged 1 commit into from
Jan 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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