chiark / gitweb /
Update CHANGES.html
[disorder] / plugins / fs.c
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
5aff007d 3 * Copyright (C) 2004, 2007, 2008 Richard Kettlewell
460b9539 4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
460b9539 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
460b9539 8 * (at your option) any later version.
9 *
e7eb3a27
RK
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
460b9539 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
460b9539 17 */
132a5a4a
RK
18/** @file plugins/fs.c
19 * @brief Plugin to find tracks in a filesystem
20 */
460b9539 21#include <config.h>
22
23#include <string.h>
24#include <stdlib.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <syslog.h>
28#include <errno.h>
29#include <dirent.h>
30#include <stdio.h>
31#include <unistd.h>
32
33#include <disorder.h>
34
35void disorder_scan(const char *path) {
36 struct stat sb;
37 DIR *dp;
38 struct dirent *de;
39 char *np;
40
41 if(stat(path, &sb) < 0) {
ac06ceb3 42 disorder_error(errno, "cannot stat %s", path);
460b9539 43 return;
44 }
460b9539 45 if(S_ISDIR(sb.st_mode)) {
46 if(!(dp = opendir(path))) {
47 disorder_error(errno, "cannot open directory %s", path);
48 return;
49 }
50 while((errno = 0),
51 (de = readdir(dp))) {
52 if(de->d_name[0] != '.') {
53 disorder_asprintf(&np, "%s/%s", path, de->d_name);
54 disorder_scan(np);
55 }
56 }
57 if(errno)
58 disorder_error(errno, "error reading directory %s", path);
59 closedir(dp);
ac06ceb3
RK
60 } else if(S_ISREG(sb.st_mode)) {
61 if(access(path, R_OK) < 0) {
62 disorder_error(errno, "cannot access file %s", path);
63 return;
64 }
460b9539 65 if(printf("%s%c", path, 0) < 0)
66 disorder_fatal(errno, "error writing to scanner output pipe");
ac06ceb3 67 }
460b9539 68}
69
70int disorder_check(const char attribute((unused)) *root, const char *path) {
71 if(access(path, R_OK) == 0)
72 return 1;
73 else if(errno == ENOENT)
74 return 0;
75 else {
76 disorder_error(errno, "cannot access %s", path);
77 return -1;
78 }
79}
80
81/*
82Local Variables:
83c-basic-offset:2
84comment-column:40
85End:
86*/