Define grub_util_is_directory/regular/special_file and
use OS-dependent versions rather than to rely on stat().
This commit is contained in:
parent
ec16e02639
commit
df1e64c98e
6 changed files with 113 additions and 31 deletions
|
@ -1,3 +1,8 @@
|
|||
2013-10-15 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
Define grub_util_is_directory/regular/special_file and
|
||||
use OS-dependent versions rather than to rely on stat().
|
||||
|
||||
2013-10-15 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
* util/grub-mkimage.c: Move backend part to ...
|
||||
|
|
|
@ -30,11 +30,8 @@
|
|||
#include <grub/emu/hostdisk.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
|
||||
static int
|
||||
|
@ -52,10 +49,7 @@ is_dir (const char *path, const char *name)
|
|||
|
||||
strcat (pathname, name);
|
||||
|
||||
struct stat st;
|
||||
if (stat (pathname, &st))
|
||||
return 0;
|
||||
return S_ISDIR (st.st_mode);
|
||||
return grub_util_is_directory (pathname);
|
||||
}
|
||||
|
||||
struct grub_hostfs_data
|
||||
|
|
|
@ -216,4 +216,36 @@ grub_util_fopen (const char *path, const char *mode)
|
|||
return fopen (path, mode);
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_directory (const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat (path, &st) == -1)
|
||||
return 0;
|
||||
|
||||
return S_ISDIR (st.st_mode);
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_regular (const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat (path, &st) == -1)
|
||||
return 0;
|
||||
|
||||
return S_ISREG (st.st_mode);
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_special_file (const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (lstat (path, &st) == -1)
|
||||
return 1;
|
||||
return (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -410,6 +410,39 @@ grub_util_unlink (const char *name)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_directory (const char *name)
|
||||
{
|
||||
LPTSTR name_windows;
|
||||
DWORD attr;
|
||||
|
||||
name_windows = grub_util_get_windows_path (name);
|
||||
if (!name_windows)
|
||||
return 0;
|
||||
|
||||
attr = GetFileAttributes (name_windows);
|
||||
grub_free (name_windows);
|
||||
|
||||
return !!(attr & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_regular (const char *name)
|
||||
{
|
||||
LPTSTR name_windows;
|
||||
DWORD attr;
|
||||
|
||||
name_windows = grub_util_get_windows_path (name);
|
||||
if (!name_windows)
|
||||
return 0;
|
||||
|
||||
attr = GetFileAttributes (name_windows);
|
||||
grub_free (name_windows);
|
||||
|
||||
return !(attr & FILE_ATTRIBUTE_DIRECTORY)
|
||||
&& !(attr & FILE_ATTRIBUTE_REPARSE_POINT) && attr;
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
|
||||
FILE *
|
||||
|
@ -438,6 +471,22 @@ int fsync (int fno)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_special_file (const char *name)
|
||||
{
|
||||
LPTSTR name_windows;
|
||||
DWORD attr;
|
||||
|
||||
name_windows = grub_util_get_windows_path (name);
|
||||
if (!name_windows)
|
||||
return 1;
|
||||
|
||||
attr = GetFileAttributes (name_windows);
|
||||
grub_free (name_windows);
|
||||
|
||||
return !!(attr & FILE_ATTRIBUTE_REPARSE_POINT) || !attr;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
FILE *
|
||||
|
@ -446,4 +495,14 @@ grub_util_fopen (const char *path, const char *mode)
|
|||
return fopen (path, mode);
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_special_file (const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (lstat (destnew, &st) == -1)
|
||||
return 1;
|
||||
return (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,13 @@
|
|||
#include <sys/types.h>
|
||||
#include <grub/osdep/hostfile.h>
|
||||
|
||||
int
|
||||
grub_util_is_directory (const char *path);
|
||||
int
|
||||
grub_util_is_special_file (const char *path);
|
||||
int
|
||||
grub_util_is_regular (const char *path);
|
||||
|
||||
int
|
||||
grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off);
|
||||
ssize_t
|
||||
|
|
|
@ -34,18 +34,11 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/zfs/zfs.h>
|
||||
#include <grub/osdep/hostfile.h>
|
||||
#include <grub/emu/hostfile.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "progname.h"
|
||||
#include "argp.h"
|
||||
|
@ -265,22 +258,17 @@ cmd_cmp (char *src, char *dest)
|
|||
{
|
||||
FILE *ff;
|
||||
|
||||
struct stat st;
|
||||
if (stat (dest, &st) == -1)
|
||||
grub_util_error (_("OS file %s open error: %s"), dest,
|
||||
strerror (errno));
|
||||
|
||||
if (S_ISDIR (st.st_mode))
|
||||
if (grub_util_is_directory (dest))
|
||||
{
|
||||
DIR *dir = opendir (dest);
|
||||
struct dirent *entry;
|
||||
grub_util_fd_dir_t dir = grub_util_fd_opendir (dest);
|
||||
grub_util_fd_dirent_t entry;
|
||||
if (dir == NULL)
|
||||
{
|
||||
grub_util_error (_("OS file %s open error: %s"), dest,
|
||||
strerror (errno));
|
||||
grub_util_fd_strerror ());
|
||||
return;
|
||||
}
|
||||
while ((entry = readdir (dir)))
|
||||
while ((entry = grub_util_fd_readdir (dir)))
|
||||
{
|
||||
char *srcnew, *destnew;
|
||||
char *ptr;
|
||||
|
@ -298,15 +286,12 @@ cmd_cmp (char *src, char *dest)
|
|||
*ptr++ = '/';
|
||||
strcpy (ptr, entry->d_name);
|
||||
|
||||
#if !defined (_WIN32) || defined (__CYGWIN__)
|
||||
if (lstat (destnew, &st) == -1 || (!S_ISREG (st.st_mode)
|
||||
&& !S_ISDIR (st.st_mode)))
|
||||
if (grub_util_is_special_file (destnew))
|
||||
continue;
|
||||
#endif
|
||||
|
||||
cmd_cmp (srcnew, destnew);
|
||||
}
|
||||
closedir (dir);
|
||||
grub_util_fd_closedir (dir);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue