|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
Copyright (C) 2011 ABRT Team
|
|
Packit Service |
779887 |
Copyright (C) 2011 RedHat inc.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
779887 |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
779887 |
the Free Software Foundation; either version 2 of the License, or
|
|
Packit Service |
779887 |
(at your option) any later version.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
779887 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
779887 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
779887 |
GNU General Public License for more details.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
You should have received a copy of the GNU General Public License along
|
|
Packit Service |
779887 |
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit Service |
779887 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
#include "internal_libreport.h"
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
GList *get_file_list(const char *path, const char *ext_filter)
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
/* Load .$ext files */
|
|
Packit Service |
779887 |
DIR *dir;
|
|
Packit Service |
779887 |
dir = opendir(path);
|
|
Packit Service |
779887 |
if (!dir)
|
|
Packit Service |
779887 |
return NULL;
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
GList *files = NULL;
|
|
Packit Service |
779887 |
struct dirent *dent;
|
|
Packit Service |
779887 |
while ((dent = readdir(dir)) != NULL)
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
/* skip . and .. */
|
|
Packit Service |
779887 |
if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0)
|
|
Packit Service |
779887 |
continue;
|
|
Packit Service |
779887 |
char *fullname = concat_path_file(path, dent->d_name);
|
|
Packit Service |
779887 |
char *ext = NULL;
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
if (ext_filter)
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
ext = strrchr(dent->d_name, '.');
|
|
Packit Service |
779887 |
if (!ext)
|
|
Packit Service |
779887 |
continue;
|
|
Packit Service |
779887 |
if (ext_filter && strcmp(ext + 1, ext_filter) != 0)
|
|
Packit Service |
779887 |
continue;
|
|
Packit Service |
779887 |
*ext = '\0';
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
//TODO: get rid of special handling of symlinks?
|
|
Packit Service |
779887 |
struct stat buf;
|
|
Packit Service |
779887 |
if (0 != lstat(fullname, &buf))
|
|
Packit Service |
779887 |
goto next;
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
if (S_ISLNK(buf.st_mode))
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
GError *error = NULL;
|
|
Packit Service |
779887 |
gchar *link = g_file_read_link(fullname, &error);
|
|
Packit Service |
779887 |
if (error != NULL)
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
error_msg("Error reading symlink '%s': %s", fullname, error->message);
|
|
Packit Service |
779887 |
goto next;
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
gchar *target = g_path_get_basename(link);
|
|
Packit Service |
779887 |
log_debug("Symlink '%s' is pointing to '%s'", link, target);
|
|
Packit Service |
779887 |
if (ext_filter)
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
char *ext = strrchr(target, '.');
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
if (!ext || 0 != strcmp(ext + 1, ext_filter))
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
error_msg("Invalid event symlink '%s': expected it to"
|
|
Packit Service |
779887 |
" point to another '%s' file", fullname, ext_filter);
|
|
Packit Service |
779887 |
goto next;
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
*ext = '\0';
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
free(fullname);
|
|
Packit Service |
779887 |
fullname = concat_path_file(path, target);
|
|
Packit Service |
779887 |
files = g_list_prepend(files, new_file_obj(fullname, target));
|
|
Packit Service |
779887 |
g_free(link);
|
|
Packit Service |
779887 |
g_free(target);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
goto next;
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
file_obj_t *file = new_file_obj(fullname, dent->d_name);
|
|
Packit Service |
779887 |
files = g_list_prepend(files, file);
|
|
Packit Service |
779887 |
next:
|
|
Packit Service |
779887 |
free(fullname);
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
closedir(dir);
|
|
Packit Service |
779887 |
return files;
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
void free_file_list(GList *filelist)
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
g_list_free_full(filelist, (GDestroyNotify)free_file_obj);
|
|
Packit Service |
779887 |
}
|