Improved handling of symbolic links.

This commit is contained in:
sorgelig
2019-01-19 02:38:10 +08:00
parent 85c78c679f
commit 325f6b6ce4

View File

@@ -1058,6 +1058,8 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons
}
sprintf(full_path, "%s/%s", getRootDir(), path);
int path_len = strlen(full_path);
printf("Start to scan %sdir: %s\n", is_zipped ? "zipped " : "", full_path);
char *zip_path, *file_path_in_zip = (char*)"";
@@ -1122,25 +1124,24 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons
de = &_de;
}
if (de->d_type == DT_LNK)
// Handle symbolic link type in the directory entry
// Handle (possible) symbolic link type in the directory entry
if (de->d_type == DT_LNK || de->d_type == DT_REG)
{
char *new_full_path = (char *) malloc (strlen(full_path)+strlen(de->d_name)+2);
sprintf(new_full_path, "%s/%s", full_path, de->d_name);
sprintf(full_path+path_len, "/%s", de->d_name);
struct stat entrystat;
if (!stat( new_full_path, &entrystat ))
{
if ( S_ISREG(entrystat.st_mode))
if (!stat(full_path, &entrystat))
{
if (S_ISREG(entrystat.st_mode))
{
de->d_type = DT_REG;
}
else if (S_ISDIR(entrystat.st_mode))
{
de->d_type = DT_DIR;
de->d_type = DT_DIR;
}
}
free(new_full_path);
}
if (de->d_type == DT_DIR)