ci: pin rust toolchain and make takeout walker compile on windows
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "stable"
|
||||||
@@ -7,11 +7,27 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
#[cfg(unix)]
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
#[cfg(windows)]
|
||||||
|
use std::os::windows::fs::MetadataExt;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use crate::logging::Logger;
|
use crate::logging::Logger;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn fingerprint(metadata: &fs::Metadata) -> (u64, u64) {
|
||||||
|
(metadata.dev(), metadata.ino())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn fingerprint(metadata: &fs::Metadata) -> (u64, u64) {
|
||||||
|
(
|
||||||
|
u64::from(metadata.volume_serial_number().unwrap_or(0)),
|
||||||
|
metadata.file_index().unwrap_or(0),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum FileKind {
|
pub enum FileKind {
|
||||||
Mbox,
|
Mbox,
|
||||||
@@ -73,7 +89,7 @@ fn walk_dir(
|
|||||||
logger: Logger,
|
logger: Logger,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let metadata = fs::metadata(dir)?;
|
let metadata = fs::metadata(dir)?;
|
||||||
let key = (metadata.dev(), metadata.ino());
|
let key = fingerprint(&metadata);
|
||||||
if !visited.insert(key) {
|
if !visited.insert(key) {
|
||||||
result.symlink_cycles += 1;
|
result.symlink_cycles += 1;
|
||||||
logger.warn(&format!(
|
logger.warn(&format!(
|
||||||
@@ -148,6 +164,7 @@ fn classify(path: &Path) -> Option<FileKind> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
#[cfg(unix)]
|
||||||
use std::os::unix::fs::symlink;
|
use std::os::unix::fs::symlink;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
@@ -236,6 +253,7 @@ mod tests {
|
|||||||
assert_eq!(r.by_kind(FileKind::Vcf).count(), 0);
|
assert_eq!(r.by_kind(FileKind::Vcf).count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn symlink_to_directory_is_followed_once_not_infinitely() {
|
fn symlink_to_directory_is_followed_once_not_infinitely() {
|
||||||
let td = TempDir::new().unwrap();
|
let td = TempDir::new().unwrap();
|
||||||
@@ -246,6 +264,7 @@ mod tests {
|
|||||||
assert_eq!(r.files.len(), 1);
|
assert_eq!(r.files.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn symlink_cycle_is_broken() {
|
fn symlink_cycle_is_broken() {
|
||||||
let td = TempDir::new().unwrap();
|
let td = TempDir::new().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user