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

build: update dependencies #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
widestring = "1.0.2"
memoffset = "0.6.4"
windows = { version = "0.33.0", features = [
"alloc",
widestring = "1.1.0"
windows = { version = "0.52.0", features = [
"Win32_Foundation",
"Win32_Storage_CloudFilters",
"Win32_System_SystemServices",
Expand All @@ -30,8 +28,9 @@ windows = { version = "0.33.0", features = [
"Storage_Streams",
"Win32_System_Ioctl",
"Win32_Security",
"Win32_System_Variant",
] }
globset = { version = "0.4.9", optional = true }
globset = { version = "0.4.14", optional = true }

[features]
# Enable globs in the `info::FetchPlaceholders` struct.
Expand Down
4 changes: 2 additions & 2 deletions examples/sftp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl SyncFilter for Filter {
let parent = absolute.strip_prefix(&client_path).unwrap();

let dirs = self.sftp.readdir(parent).unwrap();
let placeholders = dirs
let mut placeholders = dirs
.into_iter()
.filter(|(path, _)| !Path::new(&client_path).join(path).exists())
.map(|(path, stat)| {
Expand All @@ -354,7 +354,7 @@ impl SyncFilter for Filter {
})
.collect::<Vec<_>>();

ticket.pass_with_placeholder(placeholders).unwrap();
ticket.pass_with_placeholder(&mut placeholders).unwrap();
}

fn closed(&self, request: Request, info: info::Closed) {
Expand Down
6 changes: 4 additions & 2 deletions src/command/executor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{mem, ptr};
use std::{
mem::{self, offset_of},
ptr,
};

use memoffset::offset_of;
use windows::{
core,
Win32::Storage::CloudFilters::{
Expand Down
41 changes: 18 additions & 23 deletions src/ext/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{
mem::{self, MaybeUninit},
ops::{Bound, Range, RangeBounds},
os::windows::{io::AsRawHandle, prelude::RawHandle},
ptr,
};

use widestring::U16CStr;
Expand Down Expand Up @@ -58,13 +57,11 @@ pub trait FileExt: AsRawHandle {
unsafe {
CfConvertToPlaceholder(
HANDLE(self.as_raw_handle() as isize),
options
.blob
.map_or(ptr::null(), |blob| blob.as_ptr() as *const _),
options.blob.map(|blob| blob.as_ptr() as *const _),
options.blob.map_or(0, |blob| blob.len() as u32),
options.flags,
usn.as_mut_ptr(),
ptr::null_mut(),
Some(usn.as_mut_ptr()),
None,
)
.map(|_| usn.assume_init() as Usn)
}
Expand All @@ -82,7 +79,7 @@ pub trait FileExt: AsRawHandle {
CfRevertPlaceholder(
HANDLE(self.as_raw_handle() as isize),
CloudFilters::CF_REVERT_FLAG_NONE,
ptr::null_mut(),
None,
)
}
}
Expand All @@ -104,19 +101,18 @@ pub trait FileExt: AsRawHandle {
/// * The handle must have write access.
/// * [CloudErrorKind::AccessDenied][crate::CloudErrorKind::AccessDenied]
// TODO: this could be split into multiple functions to make common patterns easier
fn update(&self, usn: Usn, mut options: UpdateOptions) -> core::Result<Usn> {
fn update(&self, usn: Usn, options: UpdateOptions) -> core::Result<Usn> {
let mut usn = usn as i64;
unsafe {
CfUpdatePlaceholder(
HANDLE(self.as_raw_handle() as isize),
options.metadata.map_or(ptr::null(), |x| &x.0 as *const _),
options.blob.map_or(ptr::null(), |x| x.as_ptr() as *const _),
options.metadata.map(|x| &x.0 as *const _),
options.blob.map(|x| x.as_ptr() as *const _),
options.blob.map_or(0, |x| x.len() as u32),
options.dehydrate_range.as_mut_ptr(),
options.dehydrate_range.len() as u32,
Some(&options.dehydrate_range),
options.flags,
&mut usn as *mut _,
ptr::null_mut(),
Some(&mut usn as *mut _),
None,
)
.map(|_| usn as Usn)
}
Expand All @@ -140,7 +136,7 @@ pub trait FileExt: AsRawHandle {
Bound::Unbounded => -1,
},
CloudFilters::CF_HYDRATE_FLAG_NONE,
ptr::null_mut(),
None,
)
}
}
Expand Down Expand Up @@ -168,7 +164,7 @@ pub trait FileExt: AsRawHandle {
buffer.len() as i64,
buffer as *mut _ as *mut _,
buffer.len() as u32,
&mut length as *mut _,
Some(&mut length as *mut _),
)
}
.map(|_| length)
Expand All @@ -190,7 +186,7 @@ pub trait FileExt: AsRawHandle {
CloudFilters::CF_PLACEHOLDER_INFO_STANDARD,
data.as_mut_ptr() as *mut _,
data.len() as u32,
ptr::null_mut(),
None,
)?;
}

Expand All @@ -215,8 +211,7 @@ pub trait FileExt: AsRawHandle {
FileSystem::FileAttributeTagInfo,
info.as_mut_ptr() as *mut _,
mem::size_of::<FILE_ATTRIBUTE_TAG_INFO>() as u32,
)
.ok()?;
)?;

PlaceholderState::try_from_win32(CfGetPlaceholderStateFromFileInfo(
&info.assume_init() as *const _ as *const _,
Expand All @@ -232,7 +227,7 @@ pub trait FileExt: AsRawHandle {
HANDLE(self.as_raw_handle() as isize),
state.into(),
options.0,
ptr::null_mut(),
None,
)
}
}
Expand Down Expand Up @@ -275,7 +270,7 @@ pub trait FileExt: AsRawHandle {
CF_SYNC_ROOT_INFO_STANDARD,
data.as_mut_ptr() as *mut _,
data.len() as u32,
ptr::null_mut(),
None,
)?;
}

Expand Down Expand Up @@ -309,7 +304,7 @@ fn mark_sync_state(handle: RawHandle, sync: bool, usn: Usn) -> core::Result<Usn>
CloudFilters::CF_IN_SYNC_STATE_NOT_IN_SYNC
},
CloudFilters::CF_SET_IN_SYNC_FLAG_NONE,
&mut usn as *mut _,
Some(&mut usn as *mut _),
)
.map(|_| usn as u64)
}
Expand Down Expand Up @@ -341,7 +336,7 @@ fn dehydrate<T: RangeBounds<u64>>(
} else {
CloudFilters::CF_DEHYDRATE_FLAG_BACKGROUND
},
ptr::null_mut(),
None,
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ext/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ where
/// Information about the sync root that the path is located in.
fn sync_root_info(&self) -> core::Result<StorageProviderSyncRootInfo> {
StorageProviderSyncRootManager::GetSyncRootInformationForFolder(
StorageFolder::GetFolderFromPathAsync(
&U16String::from_os_str(self.as_ref().as_os_str()).to_hstring(),
&StorageFolder::GetFolderFromPathAsync(
&U16String::from_os_str(self.as_ref().as_os_str()).to_hstring()?,
)?
.get()?,
)
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ pub mod command;
mod error;
/// Contains traits extending common structs from the [std][std].
pub mod ext;
pub mod filter;
pub mod placeholder;
pub mod placeholder_file;
pub mod request;
pub mod root;
pub mod usn;
mod filter;
mod placeholder;
mod placeholder_file;
mod request;
mod root;
mod usn;
mod utility;

pub use error::CloudErrorKind;
Expand Down
35 changes: 20 additions & 15 deletions src/placeholder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@ use std::{
mem::ManuallyDrop,
ops::Range,
path::{Path, PathBuf},
ptr,
};

use widestring::U16CString;
use windows::{
core::{self, GUID},
core::{self, GUID, PCWSTR},
Win32::{
Storage::{
CloudFilters::{self, CfReportProviderProgress, CF_CONNECTION_KEY},
EnhancedStorage,
},
System::{
Com::StructuredStorage::{
PROPVARIANT, PROPVARIANT_0, PROPVARIANT_0_0, PROPVARIANT_0_0_0,
InitPropVariantFromUInt64Vector, PROPVARIANT, PROPVARIANT_0, PROPVARIANT_0_0,
PROPVARIANT_0_0_0,
},
Ole::VT_UI4,
Variant::VT_UI4,
},
UI::Shell::{
self, IShellItem2,
PropertiesSystem::{
self, IPropertyStore, InitPropVariantFromUInt64Vector, PROPERTYKEY,
},
PropertiesSystem::{self, IPropertyStore, PROPERTYKEY},
SHChangeNotify, SHCreateItemFromParsingName,
},
},
Expand Down Expand Up @@ -143,34 +141,41 @@ impl Placeholder {
completed as i64,
)?;

let item: IShellItem2 = SHCreateItemFromParsingName(self.path.as_os_str(), None)?;
let item: IShellItem2 = SHCreateItemFromParsingName(
PCWSTR::from_raw(
U16CString::from_os_str(self.path.as_os_str())
.unwrap()
.as_ptr(),
),
None,
)?;
let store: IPropertyStore = item.GetPropertyStore(
PropertiesSystem::GPS_READWRITE | PropertiesSystem::GPS_VOLATILEPROPERTIESONLY,
)?;

let progress = InitPropVariantFromUInt64Vector(&mut [completed, total] as *mut _, 2)?;
let progress = InitPropVariantFromUInt64Vector(Some(&[completed, total]))?;
store.SetValue(
&STORAGE_PROVIDER_TRANSFER_PROGRESS as *const _,
&progress as *const _,
)?;

let status = InitPropVariantFromUInt32(if completed < total {
PropertiesSystem::STS_TRANSFERRING.0
PropertiesSystem::STS_TRANSFERRING.0 as u32
} else {
PropertiesSystem::STS_NONE.0
PropertiesSystem::STS_NONE.0 as u32
});
store.SetValue(
&EnhancedStorage::PKEY_SyncTransferStatus as *const _,
&status as *const _,
&status,
)?;

store.Commit()?;

SHChangeNotify(
Shell::SHCNE_UPDATEITEM,
Shell::SHCNF_PATHW,
U16CString::from_os_str_unchecked(self.path.as_os_str()).as_ptr() as *const _,
ptr::null_mut(),
Some(U16CString::from_os_str_unchecked(self.path.as_os_str()).as_ptr() as *const _),
None,
);

Ok(())
Expand Down Expand Up @@ -320,7 +325,7 @@ fn InitPropVariantFromUInt32(ulVal: u32) -> PROPVARIANT {
PROPVARIANT {
Anonymous: PROPVARIANT_0 {
Anonymous: ManuallyDrop::new(PROPVARIANT_0_0 {
vt: VT_UI4.0 as u16,
vt: VT_UI4,
Anonymous: PROPVARIANT_0_0_0 { ulVal },
..Default::default()
}),
Expand Down
24 changes: 13 additions & 11 deletions src/placeholder_file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs, os::windows::prelude::MetadataExt, path::Path, ptr, slice};
use std::{fs, os::windows::prelude::MetadataExt, path::Path, slice};

use widestring::U16CString;
use windows::{
Expand All @@ -18,7 +18,7 @@ use crate::usn::Usn;

// TODO: this struct could probably have a better name to represent files/dirs
/// A builder for creating new placeholder files/directories.
#[repr(C)]
#[repr(transparent)]
#[derive(Debug)]
pub struct PlaceholderFile(CF_PLACEHOLDER_CREATE_INFO);

Expand Down Expand Up @@ -120,14 +120,13 @@ impl PlaceholderFile {
///
/// If you need to create placeholders from the [SyncFilter::fetch_placeholders][crate::SyncFilter::fetch_placeholders] callback, do not use this method. Instead, use
/// [FetchPlaceholders::pass_with_placeholders][crate::ticket::FetchPlaceholders::pass_with_placeholders].
pub fn create<P: AsRef<Path>>(mut self, parent: impl AsRef<Path>) -> core::Result<Usn> {
pub fn create<P: AsRef<Path>>(self, parent: impl AsRef<Path>) -> core::Result<Usn> {
unsafe {
CfCreatePlaceholders(
parent.as_ref().as_os_str(),
&mut self as *mut _ as *mut _,
1,
PCWSTR::from_raw(U16CString::from_os_str(parent.as_ref()).unwrap().as_ptr()),
&mut [self.0],
CloudFilters::CF_CREATE_FLAG_NONE,
ptr::null_mut(),
None,
)?;
}

Expand Down Expand Up @@ -161,11 +160,14 @@ impl BatchCreate for [PlaceholderFile] {
fn create<P: AsRef<Path>>(&mut self, path: P) -> core::Result<Vec<core::Result<Usn>>> {
unsafe {
CfCreatePlaceholders(
path.as_ref().as_os_str(),
self.as_mut_ptr() as *mut CF_PLACEHOLDER_CREATE_INFO,
self.len() as u32,
PCWSTR::from_raw(U16CString::from_os_str(path.as_ref()).unwrap().as_ptr()),
// TODO: we should be able to cast it directly to its inner type
&mut self
.iter()
.map(|placeholder| placeholder.0)
.collect::<Vec<_>>(),
CloudFilters::CF_CREATE_FLAG_NONE,
ptr::null_mut(),
None,
)?;
}

Expand Down
2 changes: 1 addition & 1 deletion src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use windows::Win32::Storage::CloudFilters::{CF_CALLBACK_INFO, CF_PROCESS_INFO};

use crate::placeholder::Placeholder;

pub type RawConnectionKey = isize;
pub type RawConnectionKey = i64;
pub type RawTransferKey = i64;

/// A struct containing various information for the current file operation.
Expand Down
Loading