Skip to content

Commit ac8decf

Browse files
factorydroidechobt
authored andcommitted
fix(debug): show symlink metadata instead of target metadata
Fixes bounty issue #1577 The `cortex debug file` command was using `std::fs::metadata()` which follows symlinks and returns metadata about the target file. This caused symlinks to be displayed as their target type instead of showing they are symlinks. Changed to use `std::fs::symlink_metadata()` to get information about the symlink itself. Also added a `symlink_target` field that shows where the symlink points to when inspecting symlinks.
1 parent 10d003a commit ac8decf

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

cortex-cli/src/debug_cmd.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ struct FileMetadata {
301301
is_dir: bool,
302302
is_symlink: bool,
303303
#[serde(skip_serializing_if = "Option::is_none")]
304+
symlink_target: Option<String>,
305+
#[serde(skip_serializing_if = "Option::is_none")]
304306
modified: Option<String>,
305307
#[serde(skip_serializing_if = "Option::is_none")]
306308
created: Option<String>,
@@ -317,7 +319,8 @@ async fn run_file(args: FileArgs) -> Result<()> {
317319
let exists = path.exists();
318320

319321
let (metadata, error) = if exists {
320-
match std::fs::metadata(&path) {
322+
// Use symlink_metadata to get info about the symlink itself, not the target
323+
match std::fs::symlink_metadata(&path) {
321324
Ok(meta) => {
322325
let modified = meta
323326
.modified()
@@ -328,12 +331,22 @@ async fn run_file(args: FileArgs) -> Result<()> {
328331
.ok()
329332
.map(|t| chrono::DateTime::<chrono::Utc>::from(t).to_rfc3339());
330333

334+
// Get symlink target if this is a symlink
335+
let symlink_target = if meta.file_type().is_symlink() {
336+
std::fs::read_link(&path)
337+
.ok()
338+
.map(|p| p.display().to_string())
339+
} else {
340+
None
341+
};
342+
331343
(
332344
Some(FileMetadata {
333345
size: meta.len(),
334346
is_file: meta.is_file(),
335347
is_dir: meta.is_dir(),
336348
is_symlink: meta.file_type().is_symlink(),
349+
symlink_target,
337350
modified,
338351
created,
339352
readonly: meta.permissions().readonly(),
@@ -398,6 +411,9 @@ async fn run_file(args: FileArgs) -> Result<()> {
398411
"unknown"
399412
}
400413
);
414+
if let Some(ref target) = meta.symlink_target {
415+
println!(" Target: {}", target);
416+
}
401417
println!(" Readonly: {}", meta.readonly);
402418
if let Some(ref modified) = meta.modified {
403419
println!(" Modified: {}", modified);

0 commit comments

Comments
 (0)