Merge commit 'remotes/meins/v0.3' into v0.3
authorAndre Noll <maan@systemlinux.org>
Tue, 2 Oct 2007 08:20:45 +0000 (10:20 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 2 Oct 2007 08:20:45 +0000 (10:20 +0200)
afs.cmd
aft.c
error.h
fd.c
fd.h
osl.c
vss.c

diff --git a/afs.cmd b/afs.cmd
index e6e0d3e1bb7c8a9f828ee12e17048a5b14c5cba2..2ec7bd26c3886a1bd39aa3db2eed1f0c02166584 100644 (file)
--- a/afs.cmd
+++ b/afs.cmd
@@ -17,6 +17,9 @@ H: are added recursively.
 H:
 H: Options:
 H:
+H: -a  Add all files. The default is to add only files ending in a known suffix
+H:     for a supported audio format.
+H:
 H: -l  Add files lazily. If a file already exists in the database, skip this file.
 H:     This operation is really cheap. Use it when adding large directories if only a
 H:     few files where added.
@@ -73,7 +76,7 @@ H:            -si:  sort by image id.
 H:
 H:             -sy:  sort by lyrics id.
 H:
-H:             -sb:  sort by bitrate.
+H:             -sb:  sort by bit rate.
 H:
 H:             -sd:  sort by duration.
 H:
diff --git a/aft.c b/aft.c
index 209ea525be39309ea7ea5af0479289cdc01833c3..cbea5eb1593a1ed8f0fdaa02de634a9e1f0e92e9 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1401,6 +1401,7 @@ afhi <=> force or no HS
 #define ADD_FLAG_LAZY 1
 #define ADD_FLAG_FORCE 2
 #define ADD_FLAG_VERBOSE 4
+#define ADD_FLAG_ALL 8
 
 /* TODO: change log messages so that they get written to the result buffer */
 
@@ -1564,6 +1565,14 @@ static int add_one_audio_file(const char *arg, const void *private_data)
        ret = verify_path(arg, &path);
        if (ret < 0)
                goto out_free;
+       ret = guess_audio_format(path);
+       if (ret < 0 && !(pad->flags & ADD_FLAG_ALL)) {
+               if (pad->flags & ADD_FLAG_VERBOSE)
+                       ret = send_va_buffer(pad->fd, "%s: %s\n",
+                               PARA_STRERROR(-ret), path);
+               ret = 1;
+               goto out_free;
+       }
        query.data = path;
        query.size = strlen(path) + 1;
        ret = send_callback_request(path_brother_callback, &query, &result);
@@ -1614,8 +1623,11 @@ static int add_one_audio_file(const char *arg, const void *private_data)
                format_num = ret;
                afhi_ptr = &afhi;
        }
-       if (pad->flags & ADD_FLAG_VERBOSE)
-               send_va_buffer(pad->fd, "adding %s\n", path);
+       if (pad->flags & ADD_FLAG_VERBOSE) {
+               ret = send_va_buffer(pad->fd, "adding %s\n", path);
+               if (ret < 0)
+                       goto out_unmap;
+       }
        munmap(map.data, map.size);
        save_audio_file_info(hash, path, afhi_ptr, pad->flags, format_num, &obj);
        /* Ask afs to consider this entry for adding. */
@@ -1625,14 +1637,15 @@ static int add_one_audio_file(const char *arg, const void *private_data)
 out_unmap:
        munmap(map.data, map.size);
 out_free:
-       if (ret < 0)
+       if (ret < 0 && ret != -E_SEND)
                send_va_buffer(pad->fd, "failed to add %s (%s)\n", path?
                        path : arg, PARA_STRERROR(-ret));
        free(obj.data);
        free(path);
        if (afhi_ptr)
                free(afhi_ptr->chunk_table);
-       return 1; /* it's not an error if not all files could be added */
+       /* it's not an error if not all files could be added */
+       return ret == -E_SEND? ret : 1;
 }
 
 int com_add(int fd, int argc, char * const * const argv)
@@ -1649,6 +1662,10 @@ int com_add(int fd, int argc, char * const * const argv)
                        i++;
                        break;
                }
+               if (!strcmp(arg, "-a")) {
+                       pad.flags |= ADD_FLAG_ALL;
+                       continue;
+               }
                if (!strcmp(arg, "-l")) {
                        pad.flags |= ADD_FLAG_LAZY;
                        continue;
@@ -1673,12 +1690,18 @@ int com_add(int fd, int argc, char * const * const argv)
                if (ret < 0)
                        PARA_NOTICE_LOG("failed to stat %s (%s)", path,
                                strerror(errno));
-               else
+               else {
                        if (S_ISDIR(statbuf.st_mode))
-                               for_each_file_in_dir(path, add_one_audio_file,
+                               ret = for_each_file_in_dir(path, add_one_audio_file,
                                        &pad);
                        else
-                               add_one_audio_file(path, &pad);
+                               ret = add_one_audio_file(path, &pad);
+                       if (ret < 0) {
+                               send_va_buffer(fd, "%s: %s\n", path, PARA_STRERROR(-ret));
+                               free(path);
+                               return ret;
+                       }
+               }
                free(path);
        }
        ret = 1;
diff --git a/error.h b/error.h
index b7b66c697e5c7bdb63197845892147083d3049ce..e8920d29ee8afe4d518534711a58c937d873928d 100644 (file)
--- a/error.h
+++ b/error.h
@@ -391,6 +391,7 @@ extern const char **para_errlist[];
 
 
 #define VSS_ERRORS \
+       PARA_ERROR(BAD_AUDIO_FILE_SUFFIX, "unknown suffix"), \
        PARA_ERROR(AUDIO_FORMAT, "audio format not recognized"), \
        PARA_ERROR(CHUNK, "unable to get chunk"), \
 
@@ -499,6 +500,7 @@ extern const char **para_errlist[];
        PARA_ERROR(OPENDIR, "can not open directory"), \
        PARA_ERROR(NOSPC, "no space left on device"), \
        PARA_ERROR(OPEN, "failed to open file"), \
+       PARA_ERROR(CHDIR_PERM, "insufficient permissions to chdir"), \
 
 
 #define WRITE_ERRORS \
diff --git a/fd.c b/fd.c
index 398bf2ce818345a6cc3d98648953fa05096a8b48..e5aa59f59382967ffd9c54e7c7a4199246bde1f1 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -194,7 +194,29 @@ int para_open(const char *path, int flags, mode_t mode)
                break;
        };
        PARA_ERROR_LOG("failed to open %s: %s\n", path, strerror(errno));
-       return ret;
+       return -E_OPEN;
+}
+
+/**
+ * Wrapper for chdir(2).
+ *
+ * \param path the specified directory.
+ *
+ * \return Positive on success, negative on errors.
+ */
+int para_chdir(const char *path)
+{
+       int ret = chdir(path);
+
+       if (ret >= 0)
+               return 1;
+       switch (errno) {
+       case ENOENT:
+               return -E_NOENT;
+       case EACCES:
+               return -E_CHDIR_PERM;
+       };
+       return -E_CHDIR;
 }
 
 /**
@@ -231,8 +253,8 @@ int para_opendir(const char *dirname, DIR **dir, int *cwd)
                        return ret;
                *cwd = ret;
        }
-       ret = -E_CHDIR;
-       if (chdir(dirname) < 0)
+       ret = para_chdir(dirname);
+       if (ret < 0)
                goto close_cwd;
        ret = -E_OPENDIR;
        *dir = opendir(".");
diff --git a/fd.h b/fd.h
index 9bbf7b57830fd5cd476d670e5129c550c3830cbb..823236839d723e4c1e31726a9ff26e70e61e15d3 100644 (file)
--- a/fd.h
+++ b/fd.h
@@ -17,3 +17,4 @@ int para_open(const char *path, int flags, mode_t mode);
 int para_opendir(const char *dirname, DIR **dir, int *cwd);
 int para_mkdir(const char *path, mode_t mode);
 int para_fchdir(int fd);
+int para_chdir(const char *path);
diff --git a/osl.c b/osl.c
index 6e3eeca65db2a07d308f0fd2a30995867b29dbc9..0b14447b296c736ecaed7d831e0801a45c99296f 100644 (file)
--- a/osl.c
+++ b/osl.c
@@ -211,9 +211,10 @@ out:
  * \param func The function to call for each entry.
  * \param private_data Pointer to an arbitrary data structure.
  *
- * For each regular file  in \a dirname, the supplied function \a func is
+ * For each regular file under \a dirname, the supplied function \a func is
  * called.  The full path of the regular file and the \a private_data pointer
- * are passed to \a func.
+ * are passed to \a func. Directories for which the calling process has no
+ * permissions to change to are silently ignored.
  *
  * \return On success, 1 is returned. Otherwise, this function returns a
  * negative value which indicates the kind of the error.
@@ -226,7 +227,7 @@ int for_each_file_in_dir(const char *dirname,
        int cwd_fd, ret2, ret = para_opendir(dirname, &dir, &cwd_fd);
 
        if (ret < 0)
-               return ret;
+               return ret == -E_CHDIR_PERM? 1 : ret;
        /* scan cwd recursively */
        while ((entry = readdir(dir))) {
                mode_t m;
diff --git a/vss.c b/vss.c
index e6cf59676fe4699b85501b5334de8c99b090a4f1..5b7ed320aaaa38885f208dda80ad51d690999b2c 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -233,7 +233,7 @@ int guess_audio_format(const char *name)
                        return i;
                }
        }
-       return -1;
+       return -E_BAD_AUDIO_FILE_SUFFIX;
 }
 
 static int get_audio_format(int omit)