]> granicus.if.org Git - file/commitdiff
- since the name is printed alread in the message as <name>:<message> don't
authorChristos Zoulas <christos@zoulas.com>
Wed, 6 Nov 2013 19:33:31 +0000 (19:33 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 6 Nov 2013 19:33:31 +0000 (19:33 +0000)
  repeat the name in the message
- if we could not stat, don't try to provide unreadable info
- if we could not stat, it is not an error, keep going.

src/fsmagic.c
src/magic.c

index 8ad69583afde7a1116a9b43a220a3d87abab50ce..aeefb3b976d580b499edf60b39f131f830daa92a 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.67 2013/03/17 15:43:20 christos Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.68 2013/05/28 21:24:31 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -125,14 +125,12 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 
        if (ret) {
                if (ms->flags & MAGIC_ERROR) {
-                       file_error(ms, errno, "cannot stat `%s'", fn);
+                       file_error(ms, errno, "cannot stat");
                        return -1;
                }
-               if (file_printf(ms, "cannot open `%s' (%s)",
-                   fn, strerror(errno)) == -1)
+               if (file_printf(ms, "cannot open (%s)", strerror(errno)) == -1)
                        return -1;
-               ms->event_flags |= EVENT_HAD_ERR;
-               return -1;
+               return 0;
        }
 
        ret = 1;
@@ -263,7 +261,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
                                if (handle_mime(ms, mime, "symlink") == -1)
                                        return -1;
                        } else if (file_printf(ms,
-                           "%sunreadable symlink `%s' (%s)", COMMA, fn,
+                           "%sunreadable symlink (%s)", COMMA,
                            strerror(errno)) == -1)
                                return -1;
                        break;
index f657b2068b6d5815bd7bcee37668629c7f78500c..fded8c38a487fe6b536a6e6a189a362dc646eb59 100644 (file)
@@ -33,7 +33,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: magic.c,v 1.78 2013/01/07 18:20:19 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.79 2013/09/03 08:54:47 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -373,8 +373,9 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
                        pos = lseek(fd, (off_t)0, SEEK_CUR);
        } else {
                int flags = O_RDONLY|O_BINARY;
+               int okstat = stat(inname, &sb) == 0;
 
-               if (stat(inname, &sb) == 0 && S_ISFIFO(sb.st_mode)) {
+               if (okstat && S_ISFIFO(sb.st_mode)) {
 #ifdef O_NONBLOCK
                        flags |= O_NONBLOCK;
 #endif
@@ -383,7 +384,8 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
 
                errno = 0;
                if ((fd = open(inname, flags)) < 0) {
-                       if (unreadable_info(ms, sb.st_mode, inname) == -1)
+                       if (okstat &&
+                           unreadable_info(ms, sb.st_mode, inname) == -1)
                                goto done;
                        rv = 0;
                        goto done;
@@ -418,7 +420,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
 
        } else {
                if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) {
-                       file_error(ms, errno, "cannot read `%s'", inname);
+                       file_error(ms, errno, "cannot read");
                        goto done;
                }
        }