Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fs_time_deleted attribute to TrashItem #79

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,15 @@ pub fn list() -> Result<Vec<TrashItem>, Error> {
if time_deleted.is_none() {
warn!("Could not determine the deletion time of the trash item. (The `DeletionDate` field is probably missing from the info file.) The info file path is: '{:?}'", info_path);
}
result.push(TrashItem { id, name, original_parent, time_deleted: time_deleted.unwrap_or(-1) });
let time_deleted_v = time_deleted.unwrap_or(-1);
let time_deleted_u64 = time_deleted_v as u64;
result.push(TrashItem {
id,
name,
original_parent,
time_deleted: time_deleted.unwrap_or(-1),
fs_time_deleted: time_deleted_u64,
});
} else {
warn!("Could not determine the original parent folder of the trash item. (The `Path` field is probably missing from the info file.) The info file path is: '{:?}'", info_path);
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ pub struct TrashItem {
/// moment the file was deleted.
/// Without the "chrono" feature, this will be a negative number on linux only.
pub time_deleted: i64,
pub fs_time_deleted: u64,
}

impl TrashItem {
Expand Down
32 changes: 26 additions & 6 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ pub fn list() -> Result<Vec<TrashItem>, Error> {
let original_location_variant = item2.GetProperty(&SCID_ORIGINAL_LOCATION)?;
let original_location_bstr = PropVariantToBSTR(&original_location_variant)?;
let original_location = OsString::from_wide(original_location_bstr.as_wide());
let date_deleted = get_date_deleted_unix(&item2)?;
let fs_date_deleted = get_date_deleted_fs(&item2)?;
let unix_date_deleted = date_fs_to_unix(&fs_date_deleted)?;

item_vec.push(TrashItem {
id,
name: name.into_string().map_err(|original| Error::ConvertOsString { original })?,
original_parent: PathBuf::from(original_location),
time_deleted: date_deleted,
time_deleted: unix_date_deleted,
fs_time_deleted: fs_date_deleted,
});
}
None => {
Expand Down Expand Up @@ -204,19 +206,37 @@ unsafe fn wstr_to_os_string(wstr: PWSTR) -> OsString {
OsString::from_wide(wstr_slice)
}

unsafe fn get_date_deleted_unix(item: &IShellItem2) -> Result<i64, Error> {
unsafe fn get_date_deleted_fs(item: &IShellItem2) -> Result<u64, Error> {
let time = item.GetFileTime(&SCID_DATE_DELETED)?;
let time_u64 = ((time.dwHighDateTime as u64) << 32) | (time.dwLowDateTime as u64);

Ok(time_u64)
}

fn date_fs_to_unix(date: &u64) -> Result<i64, Error> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

date should not be a reference.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I'm at my very beginning of my rust and git/github journey, so I'm not really sure of what I am doing.

/// January 1, 1970 as Windows file time
const EPOCH_AS_FILETIME: u64 = 116444736000000000;
const HUNDREDS_OF_NANOSECONDS: u64 = 10000000;

let time = item.GetFileTime(&SCID_DATE_DELETED)?;
let time_u64 = ((time.dwHighDateTime as u64) << 32) | (time.dwLowDateTime as u64);
let rel_to_linux_epoch = time_u64 - EPOCH_AS_FILETIME;
let rel_to_linux_epoch = date - EPOCH_AS_FILETIME;
let seconds_since_unix_epoch = rel_to_linux_epoch / HUNDREDS_OF_NANOSECONDS;

Ok(seconds_since_unix_epoch as i64)
}

// unsafe fn get_date_deleted_unix(item: &IShellItem2) -> Result<i64, Error> {
// /// January 1, 1970 as Windows file time
// const EPOCH_AS_FILETIME: u64 = 116444736000000000;
// const HUNDREDS_OF_NANOSECONDS: u64 = 10000000;

// let time = item.GetFileTime(&SCID_DATE_DELETED)?;
// let time_u64 = ((time.dwHighDateTime as u64) << 32) | (time.dwLowDateTime as u64);
// let rel_to_linux_epoch = time_u64 - EPOCH_AS_FILETIME;
// let seconds_since_unix_epoch = rel_to_linux_epoch / HUNDREDS_OF_NANOSECONDS;

// Ok(seconds_since_unix_epoch as i64)
// }

struct CoInitializer {}
impl CoInitializer {
fn new() -> CoInitializer {
Expand Down