From: Andre Noll Date: Tue, 2 Oct 2007 08:20:45 +0000 (+0200) Subject: Merge commit 'remotes/meins/v0.3' into v0.3 X-Git-Tag: v0.3.0~317 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=fbfc694f85103a86c18469c6fdd2f4f03c812337;hp=f771887784c73ccfb3f00e775dcf241267a54ea7 Merge commit 'remotes/meins/v0.3' into v0.3 --- diff --git a/afs.cmd b/afs.cmd index e6e0d3e1..2ec7bd26 100644 --- 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 209ea525..cbea5eb1 100644 --- 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 b7b66c69..e8920d29 100644 --- 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 398bf2ce..e5aa59f5 100644 --- 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 9bbf7b57..82323683 100644 --- 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 6e3eeca6..0b14447b 100644 --- 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 e6cf5967..5b7ed320 100644 --- 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)