mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
Identify orphaned symlinks
This commit is contained in:
parent
33953147d6
commit
8d94809897
16
src/nnn.c
16
src/nnn.c
|
@ -182,6 +182,8 @@
|
||||||
/* Entry flags */
|
/* Entry flags */
|
||||||
#define DIR_OR_LINK_TO_DIR 0x01
|
#define DIR_OR_LINK_TO_DIR 0x01
|
||||||
#define HARD_LINK 0x02
|
#define HARD_LINK 0x02
|
||||||
|
#define SYM_ORPHAN 0x04
|
||||||
|
#define FILE_MISSING 0x08
|
||||||
#define FILE_SELECTED 0x10
|
#define FILE_SELECTED 0x10
|
||||||
|
|
||||||
/* Macros to define process spawn behaviour as flags */
|
/* Macros to define process spawn behaviour as flags */
|
||||||
|
@ -4599,6 +4601,7 @@ static bool selforparent(const char *path)
|
||||||
|
|
||||||
static int dentfill(char *path, struct entry **ppdents)
|
static int dentfill(char *path, struct entry **ppdents)
|
||||||
{
|
{
|
||||||
|
uchar entflags = 0;
|
||||||
int n = 0, flags = 0;
|
int n = 0, flags = 0;
|
||||||
ulong num_saved;
|
ulong num_saved;
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
|
@ -4691,15 +4694,18 @@ static int dentfill(char *path, struct entry **ppdents)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstatat(fd, namep, &sb, flags) == -1) {
|
if (fstatat(fd, namep, &sb, flags) == -1) {
|
||||||
/* List a symlink with target missing */
|
if (flags || (fstatat(fd, namep, &sb, AT_SYMLINK_NOFOLLOW) == -1)) {
|
||||||
if (flags || (!flags && fstatat(fd, namep, &sb, AT_SYMLINK_NOFOLLOW) == -1)) {
|
/* Missing file */
|
||||||
DPRINTF_U(flags);
|
DPRINTF_U(flags);
|
||||||
if (!flags) {
|
if (!flags) {
|
||||||
DPRINTF_S(namep);
|
DPRINTF_S(namep);
|
||||||
DPRINTF_S(strerror(errno));
|
DPRINTF_S(strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entflags = FILE_MISSING;
|
||||||
memset(&sb, 0, sizeof(struct stat));
|
memset(&sb, 0, sizeof(struct stat));
|
||||||
}
|
} else /* Orphaned symlink */
|
||||||
|
entflags = SYM_ORPHAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == total_dents) {
|
if (n == total_dents) {
|
||||||
|
@ -4762,6 +4768,10 @@ static int dentfill(char *path, struct entry **ppdents)
|
||||||
dentp->size = sb.st_size;
|
dentp->size = sb.st_size;
|
||||||
#endif
|
#endif
|
||||||
dentp->flags = S_ISDIR(sb.st_mode) ? 0 : ((sb.st_nlink > 1) ? HARD_LINK : 0);
|
dentp->flags = S_ISDIR(sb.st_mode) ? 0 : ((sb.st_nlink > 1) ? HARD_LINK : 0);
|
||||||
|
if (entflags) {
|
||||||
|
dentp->flags |= entflags;
|
||||||
|
entflags = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (cfg.blkorder) {
|
if (cfg.blkorder) {
|
||||||
if (S_ISDIR(sb.st_mode)) {
|
if (S_ISDIR(sb.st_mode)) {
|
||||||
|
|
Loading…
Reference in a new issue