]> git.wh0rd.org Git - patches.git/blob - scanelf-cache-stat.patch
497b8ce69d4fc6eb0fa50642d700e74854d1ea83
[patches.git] / scanelf-cache-stat.patch
1 Index: scanelf.c
2 ===================================================================
3 RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v
4 retrieving revision 1.159
5 diff -u -p -r1.159 scanelf.c
6 --- scanelf.c   29 Oct 2006 16:20:54 -0000      1.159
7 +++ scanelf.c   28 Nov 2006 01:03:30 -0000
8 @@ -29,7 +29,7 @@ static int file_matches_list(const char 
9  static int scanelf_elfobj(elfobj *elf);
10  static int scanelf_elf(const char *filename, int fd, size_t len);
11  static int scanelf_archive(const char *filename, int fd, size_t len);
12 -static void scanelf_file(const char *filename);
13 +static void scanelf_file(const char *filename, const struct stat *st_cache);
14  static void scanelf_dir(const char *path);
15  static void scanelf_ldpath(void);
16  static void scanelf_envpath(void);
17 @@ -1231,23 +1231,30 @@ static int scanelf_archive(const char *f
18         return 0;
19  }
20  /* scan a file which may be an elf or an archive or some other magical beast */
21 -static void scanelf_file(const char *filename)
22 +static void scanelf_file(const char *filename, const struct stat *st_cache)
23  {
24 -       struct stat st;
25 +       const struct stat *st;
26 +       struct stat my_st;
27         int fd;
28  
29 -       /* make sure 'filename' exists */
30 -       if (lstat(filename, &st) == -1) {
31 -               if (be_verbose > 2) printf("%s: does not exist\n", filename);
32 -               return;
33 -       }
34 +       /* use stat cache if we have one */
35 +       if (!st_cache) {
36 +               /* make sure 'filename' exists */
37 +               if (lstat(filename, &my_st) == -1) {
38 +                       if (be_verbose > 2) printf("%s: does not exist\n", filename);
39 +                       return;
40 +               }
41 +               st = &my_st;
42 +       } else
43 +               st = st_cache;
44  
45         /* always handle regular files and handle symlinked files if no -y */
46 -       if (S_ISLNK(st.st_mode)) {
47 +       if (S_ISLNK(st->st_mode)) {
48                 if (!scan_symlink) return;
49 -               stat(filename, &st);
50 +               stat(filename, &my_st);
51 +               st = &my_st;
52         }
53 -       if (!S_ISREG(st.st_mode)) {
54 +       if (!S_ISREG(st->st_mode)) {
55                 if (be_verbose > 2) printf("%s: skipping non-file\n", filename);
56                 return;
57         }
58 @@ -1255,9 +1262,9 @@ static void scanelf_file(const char *fil
59         if ((fd=open(filename, (fix_elf ? O_RDWR : O_RDONLY))) == -1)
60                 return;
61  
62 -       if (scanelf_elf(filename, fd, st.st_size) == 1 && scan_archives)
63 +       if (scanelf_elf(filename, fd, st->st_size) == 1 && scan_archives)
64                 /* if it isn't an ELF, maybe it's an .a archive */
65 -               scanelf_archive(filename, fd, st.st_size);
66 +               scanelf_archive(filename, fd, st->st_size);
67  
68         close(fd);
69  }
70 @@ -1279,7 +1286,7 @@ static void scanelf_dir(const char *path
71  
72         /* ok, if it isn't a directory, assume we can open it */
73         if (!S_ISDIR(st_top.st_mode)) {
74 -               scanelf_file(path);
75 +               scanelf_file(path, &st_top);
76                 return;
77         }
78  
79 @@ -1303,7 +1310,7 @@ static void scanelf_dir(const char *path
80                 snprintf(buf, sizeof(buf), "%s%s%s", path, (path[pathlen-1] == '/') ? "" : "/", dentry->d_name);
81                 if (lstat(buf, &st) != -1) {
82                         if (S_ISREG(st.st_mode))
83 -                               scanelf_file(buf);
84 +                               scanelf_file(buf, &st);
85                         else if (dir_recurse && S_ISDIR(st.st_mode)) {
86                                 if (dir_crossmount || (st_top.st_dev == st.st_dev))
87                                         scanelf_dir(buf);