gs-hf 0.4.6

Fork of hf-hub. This crates aims ease the interaction with huggingface It aims to be compatible with the huggingface_hub python package, but only implements a smaller subset of functions.
Documentation
use std::os::windows::io::AsRawHandle;
use std::path::Path;
use windows_sys::Win32::Foundation::HANDLE;
use windows_sys::Win32::Storage::FileSystem::{
    LockFileEx, UnlockFile, LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY,
};

pub(crate) fn lock<F: AsRawHandle>(file: &F) -> i32 {
    unsafe {
        let mut overlapped = std::mem::zeroed();
        let flags = LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY;
        let res = LockFileEx(
            file.as_raw_handle() as HANDLE,
            flags,
            0,
            !0,
            !0,
            &mut overlapped,
        );
        1 - res
    }
}

pub(crate) fn unlock<F: AsRawHandle>(file: &F) -> i32 {
    unsafe { UnlockFile(file.as_raw_handle() as HANDLE, 0, 0, !0, !0) }
}

/// Symlink creation needs elevated privileges on most Windows setups;
/// fall back to moving the blob into place.
pub(crate) fn symlink(rel_src: &Path, src: &Path, dst: &Path) -> std::io::Result<()> {
    if std::os::windows::fs::symlink_file(rel_src, dst).is_err() {
        std::fs::rename(src, dst)?;
    }
    Ok(())
}