2019-06-12 21:00:09 +03:00
use crate ::util ::* ;
2022-11-11 23:11:55 +03:00
use cap_std ::fs ::Dir ;
use cap_tempfile ::cap_std ;
2019-06-01 00:53:10 +03:00
use ostree ::* ;
2019-05-26 20:18:12 +03:00
use std ::os ::unix ::io ::AsRawFd ;
2019-05-21 23:58:40 +03:00
#[ test ]
2019-05-26 20:18:12 +03:00
fn should_checkout_at_with_none_options ( ) {
let test_repo = TestRepo ::new ( ) ;
let checksum = test_repo . test_commit ( " test " ) ;
let checkout_dir = tempfile ::tempdir ( ) . expect ( " checkout dir " ) ;
2022-11-11 23:11:55 +03:00
let dir = Dir ::open_ambient_dir ( checkout_dir . path ( ) , cap_std ::ambient_authority ( ) ) . unwrap ( ) ;
2019-05-26 20:18:12 +03:00
test_repo
. repo
. checkout_at (
None ,
2022-11-11 23:11:55 +03:00
dir . as_raw_fd ( ) ,
2019-05-26 20:18:12 +03:00
" test-checkout " ,
& checksum ,
2022-10-25 16:03:52 +03:00
gio ::Cancellable ::NONE ,
2019-05-26 20:18:12 +03:00
)
. expect ( " checkout at " ) ;
assert_test_file ( checkout_dir . path ( ) ) ;
}
2019-05-31 21:02:02 +03:00
#[ test ]
fn should_checkout_at_with_default_options ( ) {
let test_repo = TestRepo ::new ( ) ;
let checksum = test_repo . test_commit ( " test " ) ;
let checkout_dir = tempfile ::tempdir ( ) . expect ( " checkout dir " ) ;
2022-11-11 23:11:55 +03:00
let dir = Dir ::open_ambient_dir ( checkout_dir . path ( ) , cap_std ::ambient_authority ( ) ) . unwrap ( ) ;
2019-05-31 21:02:02 +03:00
test_repo
. repo
. checkout_at (
Some ( & RepoCheckoutAtOptions ::default ( ) ) ,
2022-11-11 23:11:55 +03:00
dir . as_raw_fd ( ) ,
2019-05-31 21:02:02 +03:00
" test-checkout " ,
& checksum ,
2022-10-25 16:03:52 +03:00
gio ::Cancellable ::NONE ,
2019-05-31 21:02:02 +03:00
)
. expect ( " checkout at " ) ;
assert_test_file ( checkout_dir . path ( ) ) ;
}
2019-05-26 20:18:12 +03:00
#[ test ]
fn should_checkout_at_with_options ( ) {
let test_repo = TestRepo ::new ( ) ;
let checksum = test_repo . test_commit ( " test " ) ;
let checkout_dir = tempfile ::tempdir ( ) . expect ( " checkout dir " ) ;
2022-11-11 23:11:55 +03:00
let dir = Dir ::open_ambient_dir ( checkout_dir . path ( ) , cap_std ::ambient_authority ( ) ) . unwrap ( ) ;
2019-05-26 20:18:12 +03:00
test_repo
. repo
. checkout_at (
Some ( & RepoCheckoutAtOptions {
mode : RepoCheckoutMode ::User ,
2019-05-31 21:02:02 +03:00
overwrite_mode : RepoCheckoutOverwriteMode ::AddFiles ,
enable_fsync : true ,
devino_to_csum_cache : Some ( RepoDevInoCache ::new ( ) ) ,
2019-05-26 20:18:12 +03:00
.. Default ::default ( )
} ) ,
2022-11-11 23:11:55 +03:00
dir . as_raw_fd ( ) ,
2019-05-26 20:18:12 +03:00
" test-checkout " ,
& checksum ,
2022-10-25 16:03:52 +03:00
gio ::Cancellable ::NONE ,
2019-05-26 20:18:12 +03:00
)
. expect ( " checkout at " ) ;
assert_test_file ( checkout_dir . path ( ) ) ;
2019-05-25 01:59:22 +03:00
}
2019-05-31 22:56:44 +03:00
#[ test ]
2022-12-15 04:09:37 +03:00
#[ cfg(any(feature = " v2018_2 " , feature = " dox " )) ]
2019-05-31 22:56:44 +03:00
fn should_checkout_at_with_filter ( ) {
2020-04-01 01:50:59 +03:00
use std ::path ::Path ;
2019-05-31 22:56:44 +03:00
let test_repo = TestRepo ::new ( ) ;
let checksum = test_repo . test_commit ( " test " ) ;
let checkout_dir = tempfile ::tempdir ( ) . expect ( " checkout dir " ) ;
2022-11-11 23:11:55 +03:00
let dir = Dir ::open_ambient_dir ( checkout_dir . path ( ) , cap_std ::ambient_authority ( ) ) . unwrap ( ) ;
2019-05-31 22:56:44 +03:00
test_repo
. repo
. checkout_at (
Some ( & RepoCheckoutAtOptions {
2019-06-13 01:34:20 +03:00
filter : RepoCheckoutFilter ::new ( | _repo , path , _stat | {
2020-04-01 01:50:59 +03:00
if path = = Path ::new ( " /testdir/testfile " ) {
2019-05-31 22:56:44 +03:00
RepoCheckoutFilterResult ::Skip
} else {
RepoCheckoutFilterResult ::Allow
}
2019-06-12 21:38:46 +03:00
} ) ,
2019-05-31 22:56:44 +03:00
.. Default ::default ( )
} ) ,
2022-11-11 23:11:55 +03:00
dir . as_raw_fd ( ) ,
2019-05-31 22:56:44 +03:00
" test-checkout " ,
& checksum ,
2022-10-25 16:03:52 +03:00
gio ::Cancellable ::NONE ,
2019-05-31 22:56:44 +03:00
)
. expect ( " checkout at " ) ;
let testdir = checkout_dir . path ( ) . join ( " test-checkout " ) . join ( " testdir " ) ;
assert! ( std ::fs ::read_dir ( & testdir ) . is_ok ( ) ) ;
assert! ( std ::fs ::File ::open ( & testdir . join ( " testfile " ) ) . is_err ( ) ) ;
}