File: btrfs-loopback.rs

package info (click to toggle)
rust-clone-file 0.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 144 kB
  • sloc: sh: 28; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 1,410 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use clone_file::*;
use std::fs;

const BASE_DIR: &'static str = env!("CARGO_MANIFEST_DIR");

fn ensure_test_sh() -> anyhow::Result<()> {
    use anyhow::Context;
    fs::metadata(format!("{BASE_DIR}/.btrfs-mnt")).context("please run tests with test.sh")?;
    Ok(())
}

/*#[cfg(target_os = "linux")]
#[test]
fn clone_file_works() -> anyhow::Result<()> {
    ensure_test_sh()?;

    clone_file(
        format!("{BASE_DIR}/.btrfs-mnt/src.bin"),
        format!("{BASE_DIR}/.btrfs-mnt/dest.bin"),
    )?;

    Ok(())
}

#[cfg(target_os = "linux")]
#[test]
fn clone_file_range_works() -> anyhow::Result<()> {
    ensure_test_sh()?;

    clone_file_range(
        format!("{BASE_DIR}/.btrfs-mnt/src.bin"),
        // chopping 16K from start and 16K from end
        16 << 10,
        (50 << 20) - (16 << 10) * 2,
        format!("{BASE_DIR}/.btrfs-mnt/dest-part.bin"),
        0,
    )?;

    Ok(())
}

#[cfg(target_os = "linux")]
#[test]
fn clone_range_consistent_with_copy_range() -> anyhow::Result<()> {
    ensure_test_sh()?;

    clone_file_range(
        format!("{BASE_DIR}/.btrfs-mnt/src.bin"),
        0,
        16 << 10,
        format!("{BASE_DIR}/.btrfs-mnt/clone-range-small.bin"),
        0,
    )?;

    copy_file_range(
        format!("{BASE_DIR}/.btrfs-mnt/src.bin"),
        0,
        16 << 10,
        format!("{BASE_DIR}/.btrfs-mnt/copy-range-small.bin"),
        0,
    )?;

    Ok(())
}*/