summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2021-06-23 11:24:37 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2021-06-23 11:24:37 -0400
commit7cfa5164233a84605cfe59e93470f7770301f286 (patch)
tree135a59c253d61af3469432877f7c98bf98b3e1c2
parentbb758478e5c52bd9cee80d5eb7e92a394b07ae26 (diff)
fix broken symlinks not appearing
-rw-r--r--src/fs/entry.rs1
-rw-r--r--src/fs/metadata.rs27
2 files changed, 18 insertions, 10 deletions
diff --git a/src/fs/entry.rs b/src/fs/entry.rs
index 1069081..082a6c0 100644
--- a/src/fs/entry.rs
+++ b/src/fs/entry.rs
@@ -20,6 +20,7 @@ impl JoshutoDirEntry {
let path = direntry.path();
let metadata = JoshutoMetadata::from(&path)?;
+
let name = direntry
.file_name()
.as_os_str()
diff --git a/src/fs/metadata.rs b/src/fs/metadata.rs
index b3f6492..60e81f8 100644
--- a/src/fs/metadata.rs
+++ b/src/fs/metadata.rs
@@ -34,17 +34,24 @@ impl JoshutoMetadata {
use std::os::unix::fs::MetadataExt;
let symlink_metadata = fs::symlink_metadata(path)?;
- let metadata = fs::metadata(path)?;
-
- let _len = metadata.len();
- let _modified = metadata.modified()?;
- let _permissions = metadata.permissions();
- let (_file_type, _directory_size) = if metadata.file_type().is_dir() {
- let _directory_size = fs::read_dir(path).map(|s| s.count()).ok();
- (FileType::Directory, _directory_size)
- } else {
- (FileType::File, None)
+ let metadata = fs::metadata(path);
+ let (_len, _modified, _permissions) = match metadata.as_ref() {
+ Ok(m) => (m.len(), m.modified()?, m.permissions()),
+ Err(_) => (
+ symlink_metadata.len(),
+ symlink_metadata.modified()?,
+ symlink_metadata.permissions(),
+ ),
};
+
+ let (_file_type, _directory_size) = match metadata.as_ref() {
+ Ok(m) if m.file_type().is_dir() => {
+ let _directory_size = fs::read_dir(path).map(|s| s.count()).ok();
+ (FileType::Directory, _directory_size)
+ }
+ _ => (FileType::File, None),
+ };
+
let _link_type = match symlink_metadata.file_type().is_symlink() {
true => {
let mut link = "".to_string();
ef='#n125'>125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213