@@ -28,73 +28,73 @@ pub async fn run_file(args: FileArgs) -> Result<()> {
2828 let special_file_type = detect_special_file_type ( & path) ;
2929
3030 let ( metadata, error) = match std:: fs:: metadata ( & path) {
31- Ok ( meta) => {
32- let modified = meta
33- . modified ( )
31+ Ok ( meta) => {
32+ let modified = meta
33+ . modified ( )
34+ . ok ( )
35+ . map ( |t| chrono:: DateTime :: < chrono:: Utc > :: from ( t) . to_rfc3339 ( ) ) ;
36+ let created = meta
37+ . created ( )
38+ . ok ( )
39+ . map ( |t| chrono:: DateTime :: < chrono:: Utc > :: from ( t) . to_rfc3339 ( ) ) ;
40+
41+ // Get symlink target if applicable
42+ let symlink_target = if meta. file_type ( ) . is_symlink ( ) {
43+ std:: fs:: read_link ( & path)
3444 . ok ( )
35- . map ( |t| chrono:: DateTime :: < chrono:: Utc > :: from ( t) . to_rfc3339 ( ) ) ;
36- let created = meta
37- . created ( )
38- . ok ( )
39- . map ( |t| chrono:: DateTime :: < chrono:: Utc > :: from ( t) . to_rfc3339 ( ) ) ;
45+ . map ( |p| p. to_string_lossy ( ) . to_string ( ) )
46+ } else {
47+ None
48+ } ;
4049
41- // Get symlink target if applicable
42- let symlink_target = if meta. file_type ( ) . is_symlink ( ) {
43- std:: fs:: read_link ( & path)
44- . ok ( )
45- . map ( |p| p. to_string_lossy ( ) . to_string ( ) )
46- } else {
47- None
48- } ;
49-
50- // Check if the current user can actually write to the file
51- // This is more accurate than just checking permission bits
52- // Skip this check for special files (FIFOs, etc.) to avoid blocking
53- let readonly = if special_file_type. is_some ( ) {
54- false // Don't check writability for special files
55- } else {
56- !is_writable_by_current_user ( & path)
57- } ;
58-
59- // Check if this is a virtual filesystem (procfs, sysfs, etc.)
60- // These report size=0 in stat() but may have actual content
61- let is_virtual_fs = is_virtual_filesystem ( & path) ;
62- let stat_size = meta. len ( ) ;
63-
64- // For virtual filesystem files that report 0 size, try to read actual content size
65- let actual_size = if is_virtual_fs && stat_size == 0 && meta. is_file ( ) {
66- // Try to read the file to get actual content size
67- // Limit read to 1MB to avoid hanging on infinite streams
68- match std:: fs:: read ( & path) {
69- Ok ( content) if !content. is_empty ( ) => Some ( content. len ( ) as u64 ) ,
70- _ => None ,
71- }
72- } else {
73- None
74- } ;
75-
76- // Get file permissions
77- let ( permissions, mode) = get_unix_permissions ( & meta) ;
78-
79- (
80- Some ( FileMetadata {
81- size : stat_size,
82- actual_size,
83- is_virtual_fs : if is_virtual_fs { Some ( true ) } else { None } ,
84- is_file : meta. is_file ( ) ,
85- is_dir : meta. is_dir ( ) ,
86- is_symlink : meta. file_type ( ) . is_symlink ( ) ,
87- file_type : special_file_type. clone ( ) ,
88- symlink_target,
89- modified,
90- created,
91- readonly,
92- permissions,
93- mode,
94- } ) ,
95- None ,
96- )
97- }
50+ // Check if the current user can actually write to the file
51+ // This is more accurate than just checking permission bits
52+ // Skip this check for special files (FIFOs, etc.) to avoid blocking
53+ let readonly = if special_file_type. is_some ( ) {
54+ false // Don't check writability for special files
55+ } else {
56+ !is_writable_by_current_user ( & path)
57+ } ;
58+
59+ // Check if this is a virtual filesystem (procfs, sysfs, etc.)
60+ // These report size=0 in stat() but may have actual content
61+ let is_virtual_fs = is_virtual_filesystem ( & path) ;
62+ let stat_size = meta. len ( ) ;
63+
64+ // For virtual filesystem files that report 0 size, try to read actual content size
65+ let actual_size = if is_virtual_fs && stat_size == 0 && meta. is_file ( ) {
66+ // Try to read the file to get actual content size
67+ // Limit read to 1MB to avoid hanging on infinite streams
68+ match std:: fs:: read ( & path) {
69+ Ok ( content) if !content. is_empty ( ) => Some ( content. len ( ) as u64 ) ,
70+ _ => None ,
71+ }
72+ } else {
73+ None
74+ } ;
75+
76+ // Get file permissions
77+ let ( permissions, mode) = get_unix_permissions ( & meta) ;
78+
79+ (
80+ Some ( FileMetadata {
81+ size : stat_size,
82+ actual_size,
83+ is_virtual_fs : if is_virtual_fs { Some ( true ) } else { None } ,
84+ is_file : meta. is_file ( ) ,
85+ is_dir : meta. is_dir ( ) ,
86+ is_symlink : meta. file_type ( ) . is_symlink ( ) ,
87+ file_type : special_file_type. clone ( ) ,
88+ symlink_target,
89+ modified,
90+ created,
91+ readonly,
92+ permissions,
93+ mode,
94+ } ) ,
95+ None ,
96+ )
97+ }
9898 Err ( e) => ( None , Some ( e. to_string ( ) ) ) ,
9999 } ;
100100
0 commit comments