| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 2 | borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#, |
| 3 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 4 | pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#}, |
| 5 | }; |
| 6 | |
| 7 | use bstrrust-analyzer cargo bstr 1.12.1 crate/::BStrrust-analyzer cargo bstr 1.12.1 bstr/BStr#; |
| 8 | use gix_filterrust-analyzer cargo gix-filter 0.30.0 crate/::{driverrust-analyzer cargo gix-filter 0.30.0 driver/::applyrust-analyzer cargo gix-filter 0.30.0 driver/apply/::MaybeDelayedrust-analyzer cargo gix-filter 0.30.0 driver/apply/MaybeDelayed#, pipelinerust-analyzer cargo gix-filter 0.30.0 pipeline/::convertrust-analyzer cargo gix-filter 0.30.0 pipeline/convert/::ToWorktreeOutcomerust-analyzer cargo gix-filter 0.30.0 pipeline/convert/ToWorktreeOutcome#}; |
| 9 | use gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::{entryrust-analyzer cargo gix-index 0.51.0 entry/::Statrust-analyzer cargo gix-index 0.51.0 entry/Stat#, Entryrust-analyzer cargo gix-index 0.51.0 Entry#}; |
| 10 | use gix_objectrust-analyzer cargo gix-object 0.60.0 crate/::FindExtrust-analyzer cargo gix-object 0.60.0 traits/find/ext/FindExt#; |
| 11 | use gix_worktreerust-analyzer cargo gix-worktree 0.52.0 crate/::Stackrust-analyzer cargo gix-worktree 0.52.0 Stack#; |
| 12 | use io_closerust-analyzer cargo io-close 0.3.7 crate/::Closerust-analyzer cargo io-close 0.3.7 Close#; |
| 13 | |
| 14 | pub struct Contextrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Context#<'a, Find> { |
| 15 | pub objectsrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Context#objects.: &'a mut Find, |
| 16 | pub path_cacherust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Context#path_cache.: &'a mut Stackrust-analyzer cargo gix-worktree 0.52.0 Stack#, |
| 17 | pub filtersrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Context#filters.: &'a mut gix_filterrust-analyzer cargo gix-filter 0.30.0 crate/::Pipelinerust-analyzer cargo gix-filter 0.30.0 Pipeline#, |
| 18 | pub bufrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Context#buf.: &'a mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 19 | } |
| 20 | |
| 21 | /// A delayed result of a long-running filter process, which is made available as stream. |
| 22 | pub struct DelayedFilteredStreamrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#<'a> { |
| 23 | /// The key identifying the driver program |
| 24 | pub keyrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#key.: gix_filterrust-analyzer cargo gix-filter 0.30.0 crate/::driverrust-analyzer cargo gix-filter 0.30.0 driver/::Keyrust-analyzer cargo gix-filter 0.30.0 driver/Key#, |
| 25 | /// If the file is going to be an executable. |
| 26 | pub needs_executable_bitrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#needs_executable_bit.: bool, |
| 27 | /// The validated path on disk at which the file should be placed. |
| 28 | pub validated_file_pathrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#validated_file_path.: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, |
| 29 | /// The entry to adjust with the file we will write. |
| 30 | pub entryrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#entry.: &'a mut gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::Entryrust-analyzer cargo gix-index 0.51.0 Entry#, |
| 31 | /// The relative path at which the entry resides (for use when querying the delayed entry). |
| 32 | pub entry_pathrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#entry_path.: &'a BStrrust-analyzer cargo bstr 1.12.1 bstr/BStr#, |
| 33 | } |
| 34 | |
| 35 | pub enum Outcomerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#<'a> { |
| 36 | /// The file was written. |
| 37 | Writtenrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#Written# { |
| 38 | /// The amount of written bytes. |
| 39 | bytesrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#Written#bytes.: usize, |
| 40 | }, |
| 41 | /// The will be ready later. |
| 42 | Delayedrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#Delayed#(DelayedFilteredStreamrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#<'a>), |
| 43 | } |
| 44 | |
| 45 | impl Outcomerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#<'_> { |
| 46 | /// Return ourselves as (in-memory) bytes if possible. |
| 47 | pub fn as_bytesrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/impl#[`Outcome<'_>`]as_bytes().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 48 | match self { |
| 49 | Outcomerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#::Writtenrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#Written# { bytesrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#Written#bytes. } => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().bytes), |
| 50 | Outcomerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#::Delayedrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#Delayed# { .. } => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | #[cfg_attr(not(unix), allow(unused_variables))] |
| 56 | pub fn checkoutrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/checkout().<'entry, Find>( |
| 57 | entry: &'entry mut Entryrust-analyzer cargo gix-index 0.51.0 Entry#, |
| 58 | entry_path: &'entry BStrrust-analyzer cargo bstr 1.12.1 bstr/BStr#, |
| 59 | Contextrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Context# { |
| 60 | objectsrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Context#objects., |
| 61 | filtersrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Context#filters., |
| 62 | path_cacherust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Context#path_cache., |
| 63 | bufrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Context#buf., |
| 64 | }: Contextrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Context#<'_, Find>, |
| 65 | craterust-analyzer cargo gix-worktree-state 0.30.0 crate/::checkoutrust-analyzer cargo gix-worktree-state 0.30.0 checkout/::chunkrust-analyzer cargo gix-worktree-state 0.30.0 checkout/chunk/::Optionsrust-analyzer cargo gix-worktree-state 0.30.0 checkout/chunk/Options# { |
| 66 | fsrust-analyzer cargo gix-worktree-state 0.30.0 checkout/chunk/Options#fs.: gix_fsrust-analyzer cargo gix-fs 0.21.0 crate/::Capabilitiesrust-analyzer cargo gix-fs 0.21.0 Capabilities# { |
| 67 | symlinkrust-analyzer cargo gix-fs 0.21.0 Capabilities#symlink., |
| 68 | executable_bitrust-analyzer cargo gix-fs 0.21.0 Capabilities#executable_bit., |
| 69 | .. |
| 70 | }, |
| 71 | destination_is_initially_emptyrust-analyzer cargo gix-worktree-state 0.30.0 checkout/chunk/Options#destination_is_initially_empty., |
| 72 | overwrite_existingrust-analyzer cargo gix-worktree-state 0.30.0 checkout/chunk/Options#overwrite_existing., |
| 73 | filter_process_delayrust-analyzer cargo gix-worktree-state 0.30.0 checkout/chunk/Options#filter_process_delay., |
| 74 | .. |
| 75 | }: craterust-analyzer cargo gix-worktree-state 0.30.0 crate/::checkoutrust-analyzer cargo gix-worktree-state 0.30.0 checkout/::chunkrust-analyzer cargo gix-worktree-state 0.30.0 checkout/chunk/::Optionsrust-analyzer cargo gix-worktree-state 0.30.0 checkout/chunk/Options#, |
| 76 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Outcomerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#<'entry>, craterust-analyzer cargo gix-worktree-state 0.30.0 crate/::checkoutrust-analyzer cargo gix-worktree-state 0.30.0 checkout/::Errorrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#> |
| 77 | where |
| 78 | Find: gix_objectrust-analyzer cargo gix-object 0.60.0 crate/::Findrust-analyzer cargo gix-object 0.60.0 traits/find/Find#, |
| 79 | { |
| 80 | let dest_relative = gix_pathrust-analyzer cargo gix-path 0.12.0 crate/::try_from_bstrrust-analyzer cargo gix-path 0.12.0 convert/try_from_bstr().(entry_path).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| craterust-analyzer cargo gix-worktree-state 0.30.0 crate/::checkoutrust-analyzer cargo gix-worktree-state 0.30.0 checkout/::Errorrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#::IllformedUtf8rust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#IllformedUtf8# { |
| 81 | pathrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#IllformedUtf8#path.: entry_path.to_ownedrust-analyzer cargo bstr 1.12.1 impls/bstring/impl#[BStr][ToOwned]to_owned().(), |
| 82 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 83 | let path_cache = path_cache.at_pathrust-analyzer cargo gix-worktree 0.52.0 stack/impl#[Stack]at_path().(dest_relative.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(entry.moderust-analyzer cargo gix-index 0.51.0 Entry#mode.), &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().objects)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 84 | let dest = path_cache.pathrust-analyzer cargo gix-worktree 0.52.0 stack/platform/impl#[`Platform<'a>`]path().(); |
| 85 | |
| 86 | let object_size = match entry.moderust-analyzer cargo gix-index 0.51.0 Entry#mode. { |
| 87 | gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::entryrust-analyzer cargo gix-index 0.51.0 entry/::Moderust-analyzer cargo gix-index 0.51.0 entry/Mode#::FILErust-analyzer cargo gix-index 0.51.0 entry/impl#[Mode]FILE. | gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::entryrust-analyzer cargo gix-index 0.51.0 entry/::Moderust-analyzer cargo gix-index 0.51.0 entry/Mode#::FILE_EXECUTABLErust-analyzer cargo gix-index 0.51.0 entry/impl#[Mode]FILE_EXECUTABLE. => { |
| 88 | let obj = (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().objects) |
| 89 | .find_blobrust-analyzer cargo gix-object 0.60.0 traits/find/ext/FindExt#find_blob().(&entry.idrust-analyzer cargo gix-index 0.51.0 Entry#id., buf) |
| 90 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| craterust-analyzer cargo gix-worktree-state 0.30.0 crate/::checkoutrust-analyzer cargo gix-worktree-state 0.30.0 checkout/::Errorrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#::Findrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#Find# { |
| 91 | errrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#Find#err., |
| 92 | pathrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#Find#path.: dest.to_path_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_path_buf().(), |
| 93 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 94 | |
| 95 | let filtered = filters.convert_to_worktreerust-analyzer cargo gix-filter 0.30.0 pipeline/convert/impl#[Pipeline]convert_to_worktree().( |
| 96 | obj.datarust-analyzer cargo gix-object 0.60.0 BlobRef#data., |
| 97 | entry_path, |
| 98 | &mut |_, attrs| { |
| 99 | path_cache.matching_attributesrust-analyzer cargo gix-worktree 0.52.0 stack/platform/impl#[`Platform<'a>`]matching_attributes().(attrs); |
| 100 | }, |
| 101 | filter_process_delay, |
| 102 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 103 | let (num_bytes, file, set_executable_after_creation) = match filtered { |
| 104 | ToWorktreeOutcomerust-analyzer cargo gix-filter 0.30.0 pipeline/convert/ToWorktreeOutcome#::Unchangedrust-analyzer cargo gix-filter 0.30.0 pipeline/convert/ToWorktreeOutcome#Unchanged#(buf) | ToWorktreeOutcomerust-analyzer cargo gix-filter 0.30.0 pipeline/convert/ToWorktreeOutcome#::Bufferrust-analyzer cargo gix-filter 0.30.0 pipeline/convert/ToWorktreeOutcome#Buffer#(buf) => { |
| 105 | let (mut file, flag) = open_filerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/open_file().( |
| 106 | dest, |
| 107 | destination_is_initially_empty, |
| 108 | overwrite_existing, |
| 109 | executable_bit, |
| 110 | entry.moderust-analyzer cargo gix-index 0.51.0 Entry#mode., |
| 111 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 112 | file.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 113 | (buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), file, flag) |
| 114 | } |
| 115 | ToWorktreeOutcomerust-analyzer cargo gix-filter 0.30.0 pipeline/convert/ToWorktreeOutcome#::Processrust-analyzer cargo gix-filter 0.30.0 pipeline/convert/ToWorktreeOutcome#Process#(MaybeDelayedrust-analyzer cargo gix-filter 0.30.0 driver/apply/MaybeDelayed#::Immediaterust-analyzer cargo gix-filter 0.30.0 driver/apply/MaybeDelayed#Immediate#(mut filtered)) => { |
| 116 | let (mut file, flag) = open_filerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/open_file().( |
| 117 | dest, |
| 118 | destination_is_initially_empty, |
| 119 | overwrite_existing, |
| 120 | executable_bit, |
| 121 | entry.moderust-analyzer cargo gix-index 0.51.0 Entry#mode., |
| 122 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 123 | let num_bytes = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::copyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/copy/copy().(&mut filtered, &mut file)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). as usize; |
| 124 | (num_bytes, file, flag) |
| 125 | } |
| 126 | ToWorktreeOutcomerust-analyzer cargo gix-filter 0.30.0 pipeline/convert/ToWorktreeOutcome#::Processrust-analyzer cargo gix-filter 0.30.0 pipeline/convert/ToWorktreeOutcome#Process#(MaybeDelayedrust-analyzer cargo gix-filter 0.30.0 driver/apply/MaybeDelayed#::Delayedrust-analyzer cargo gix-filter 0.30.0 driver/apply/MaybeDelayed#Delayed#(key)) => { |
| 127 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Outcomerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#::Delayedrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#Delayed#(DelayedFilteredStreamrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream# { |
| 128 | keyrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#key., |
| 129 | needs_executable_bitrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#needs_executable_bit.: false, |
| 130 | validated_file_pathrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#validated_file_path.: dest.to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().(), |
| 131 | entryrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#entry., |
| 132 | entry_pathrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/DelayedFilteredStream#entry_path., |
| 133 | })) |
| 134 | } |
| 135 | }; |
| 136 | |
| 137 | // For possibly existing, overwritten files, we must change the file mode explicitly. |
| 138 | finalize_entryrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/finalize_entry().(entry, file, num_bytes as u64, set_executable_after_creation)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 139 | num_bytes |
| 140 | } |
| 141 | gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::entryrust-analyzer cargo gix-index 0.51.0 entry/::Moderust-analyzer cargo gix-index 0.51.0 entry/Mode#::SYMLINKrust-analyzer cargo gix-index 0.51.0 entry/impl#[Mode]SYMLINK. => { |
| 142 | let obj = (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().objects) |
| 143 | .find_blobrust-analyzer cargo gix-object 0.60.0 traits/find/ext/FindExt#find_blob().(&entry.idrust-analyzer cargo gix-index 0.51.0 Entry#id., buf) |
| 144 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| craterust-analyzer cargo gix-worktree-state 0.30.0 crate/::checkoutrust-analyzer cargo gix-worktree-state 0.30.0 checkout/::Errorrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#::Findrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#Find# { |
| 145 | errrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#Find#err., |
| 146 | pathrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#Find#path.: dest.to_path_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_path_buf().(), |
| 147 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 148 | if symlink { |
| 149 | #[cfg_attr(not(windows), allow(unused_mut))] |
| 150 | let mut symlink_destination = Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#( |
| 151 | gix_pathrust-analyzer cargo gix-path 0.12.0 crate/::try_from_byte_slicerust-analyzer cargo gix-path 0.12.0 convert/try_from_byte_slice().(obj.datarust-analyzer cargo gix-object 0.60.0 BlobRef#data.) |
| 152 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| craterust-analyzer cargo gix-worktree-state 0.30.0 crate/::checkoutrust-analyzer cargo gix-worktree-state 0.30.0 checkout/::Errorrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#::IllformedUtf8rust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#IllformedUtf8# { pathrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#IllformedUtf8#path.: obj.datarust-analyzer cargo gix-object 0.60.0 BlobRef#data..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 153 | ); |
| 154 | #[cfg(windows)] |
| 155 | { |
| 156 | symlink_destination = gix_pathrust-analyzer cargo gix-path 0.12.0 crate/::to_native_path_on_windowsrust-analyzer cargo gix-path 0.12.0 convert/to_native_path_on_windows().(gix_pathrust-analyzer cargo gix-path 0.12.0 crate/::into_bstrrust-analyzer cargo gix-path 0.12.0 convert/into_bstr().(symlink_destination)) |
| 157 | } |
| 158 | |
| 159 | try_op_or_unlinkrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/try_op_or_unlink().(dest, overwrite_existing, |p| { |
| 160 | gix_fsrust-analyzer cargo gix-fs 0.21.0 crate/::symlinkrust-analyzer cargo gix-fs 0.21.0 symlink/::createrust-analyzer cargo gix-fs 0.21.0 symlink/create().(symlink_destination.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().(), p) |
| 161 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 162 | } else { |
| 163 | let mut file = try_op_or_unlinkrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/try_op_or_unlink().(dest, overwrite_existing, |p| { |
| 164 | open_optionsrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/open_options().(p, destination_is_initially_empty, overwrite_existing).openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().(dest) |
| 165 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 166 | file.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(obj.datarust-analyzer cargo gix-object 0.60.0 BlobRef#data.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 167 | file.closerust-analyzer cargo io-close 0.3.7 impl#[`std::fs::File`][Close]close().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 168 | } |
| 169 | |
| 170 | entry.statrust-analyzer cargo gix-index 0.51.0 Entry#stat. = Statrust-analyzer cargo gix-index 0.51.0 entry/Stat#::from_fsrust-analyzer cargo gix-index 0.51.0 entry/stat/impl#[Stat]from_fs().(&gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::fsrust-analyzer cargo gix-index 0.51.0 fs/::Metadatarust-analyzer cargo gix-index 0.51.0 fs/Metadata#::from_path_no_followrust-analyzer cargo gix-index 0.51.0 fs/impl#[Metadata]from_path_no_follow().(dest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 171 | obj.datarust-analyzer cargo gix-object 0.60.0 BlobRef#data..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() |
| 172 | } |
| 173 | gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::entryrust-analyzer cargo gix-index 0.51.0 entry/::Moderust-analyzer cargo gix-index 0.51.0 entry/Mode#::DIRrust-analyzer cargo gix-index 0.51.0 entry/impl#[Mode]DIR. => { |
| 174 | gix_featuresrust-analyzer cargo gix-features 0.48.0 crate/::tracerust-analyzer cargo gix-trace 0.1.19 crate/::warnrust-analyzer cargo gix-trace 0.1.19 warn!!( |
| 175 | "Skipped sparse directory at '{entry_path}' ({id}) as it cannot yet be handled", |
| 176 | id = entry.id |
| 177 | ); |
| 178 | 0 |
| 179 | } |
| 180 | gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::entryrust-analyzer cargo gix-index 0.51.0 entry/::Moderust-analyzer cargo gix-index 0.51.0 entry/Mode#::COMMITrust-analyzer cargo gix-index 0.51.0 entry/impl#[Mode]COMMIT. => { |
| 181 | gix_featuresrust-analyzer cargo gix-features 0.48.0 crate/::tracerust-analyzer cargo gix-trace 0.1.19 crate/::warnrust-analyzer cargo gix-trace 0.1.19 warn!!( |
| 182 | "Skipped submodule at '{entry_path}' ({id}) as it cannot yet be handled", |
| 183 | id = entry.id |
| 184 | ); |
| 185 | 0 |
| 186 | } |
| 187 | _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(), |
| 188 | }; |
| 189 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Outcomerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#::Writtenrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#Written# { bytesrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/Outcome#Written#bytes.: object_size }) |
| 190 | } |
| 191 | |
| 192 | /// Note that this works only because we assume to not race ourselves when symlinks are involved, and we do this by |
| 193 | /// delaying symlink creation to the end and will always do that sequentially. |
| 194 | /// It's still possible to fall for a race if other actors create symlinks in our path, but that's nothing to defend against. |
| 195 | fn try_op_or_unlinkrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/try_op_or_unlink().<T>( |
| 196 | path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, |
| 197 | overwrite_existing: bool, |
| 198 | op: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<T>, |
| 199 | ) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<T> { |
| 200 | if overwrite_existing { |
| 201 | match op(path) { |
| 202 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(res) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(res), |
| 203 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) if gix_fsrust-analyzer cargo gix-fs 0.21.0 crate/::symlinkrust-analyzer cargo gix-fs 0.21.0 symlink/::is_collision_errorrust-analyzer cargo gix-fs 0.21.0 symlink/is_collision_error().(&err) => { |
| 204 | try_unlink_path_recursivelyrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/try_unlink_path_recursively().(path, &stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::symlink_metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/symlink_metadata().(path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 205 | op(path) |
| 206 | } |
| 207 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err), |
| 208 | } |
| 209 | } else { |
| 210 | op(path) |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | fn try_unlink_path_recursivelyrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/try_unlink_path_recursively().(path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, path_meta: &stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/Metadata#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 215 | if path_meta.is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[Metadata]is_dir().() { |
| 216 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::remove_dir_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_dir_all().(path) |
| 217 | } else if path_meta.file_typerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[Metadata]file_type().().is_symlinkrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_symlink().() { |
| 218 | gix_fsrust-analyzer cargo gix-fs 0.21.0 crate/::symlinkrust-analyzer cargo gix-fs 0.21.0 symlink/::removerust-analyzer cargo gix-fs 0.21.0 symlink/remove().(path) |
| 219 | } else { |
| 220 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(path) |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | #[cfg(not(debug_assertions))] |
| 225 | fn debug_assert_dest_is_no_symlink(_path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) {} |
| 226 | |
| 227 | /// This is a debug assertion as we expect the machinery calling this to prevent this possibility in the first place |
| 228 | #[cfg(debug_assertions)] |
| 229 | fn debug_assert_dest_is_no_symlinkrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/debug_assert_dest_is_no_symlink().(path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) { |
| 230 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(meta) = path.metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]metadata().() { |
| 231 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!( |
| 232 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().meta.file_typerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[Metadata]file_type().().is_symlinkrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_symlink().(), |
| 233 | "BUG: should not ever allow to overwrite/write-into the target of a symbolic link: {}", |
| 234 | path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().() |
| 235 | ); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | fn open_optionsrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/open_options().(path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, destination_is_initially_empty: bool, overwrite_existing: bool) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions# { |
| 240 | if overwrite_existing || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().destination_is_initially_empty { |
| 241 | debug_assert_dest_is_no_symlinkrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/debug_assert_dest_is_no_symlink().(path); |
| 242 | } |
| 243 | let mut options = gix_featuresrust-analyzer cargo gix-features 0.48.0 crate/::fsrust-analyzer cargo gix-features 0.48.0 fs/::open_options_no_followrust-analyzer cargo gix-features 0.48.0 fs/open_options_no_follow().(); |
| 244 | options |
| 245 | .create_newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]create_new().(destination_is_initially_empty && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().overwrite_existing) |
| 246 | .createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]create().(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().destination_is_initially_empty || overwrite_existing) |
| 247 | .writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]write().(true) |
| 248 | .truncaterust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]truncate().(true); |
| 249 | options |
| 250 | } |
| 251 | |
| 252 | pub(craterust-analyzer cargo gix-worktree-state 0.30.0 crate/) fn open_filerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/open_file().( |
| 253 | path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, |
| 254 | destination_is_initially_empty: bool, |
| 255 | overwrite_existing: bool, |
| 256 | fs_supports_executable_bit: bool, |
| 257 | entry_mode: gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::entryrust-analyzer cargo gix-index 0.51.0 entry/::Moderust-analyzer cargo gix-index 0.51.0 entry/Mode#, |
| 258 | ) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#, bool)> { |
| 259 | #[cfg_attr(windows, allow(unused_mut))] |
| 260 | let mut options = open_optionsrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/open_options().(path, destination_is_initially_empty, overwrite_existing); |
| 261 | let needs_executable_bit = fs_supports_executable_bit && entry_mode rust-analyzer cargo gix-index 0.51.0 entry/impl#[Mode][`PartialEq<Self>`]eq().==rust-analyzer cargo gix-index 0.51.0 entry/impl#[Mode][`PartialEq<Self>`]eq(). rust-analyzer cargo gix-index 0.51.0 entry/impl#[Mode][`PartialEq<Self>`]eq().gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::entryrust-analyzer cargo gix-index 0.51.0 entry/::Moderust-analyzer cargo gix-index 0.51.0 entry/Mode#::FILE_EXECUTABLErust-analyzer cargo gix-index 0.51.0 entry/impl#[Mode]FILE_EXECUTABLE.; |
| 262 | #[cfg(unix)] |
| 263 | let set_executable_after_creation = if needs_executable_bit && destination_is_initially_empty { |
| 264 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/::OpenOptionsExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/OpenOptionsExt#; |
| 265 | // Note that these only work if the file was newly created, but won't if it's already |
| 266 | // existing, possibly without the executable bit set. Thus we do this only if the file is new. |
| 267 | options.moderust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/impl#[OpenOptions][OpenOptionsExt]mode().(0o777); |
| 268 | false |
| 269 | } else { |
| 270 | needs_executable_bit |
| 271 | }; |
| 272 | // not supported on windows |
| 273 | #[cfg(windows)] |
| 274 | let set_executable_after_creation = needs_executable_bit; |
| 275 | try_op_or_unlinkrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/try_op_or_unlink().(path, overwrite_existing, |p| options.openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().(p)).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|f| (f, set_executable_after_creation)) |
| 276 | } |
| 277 | |
| 278 | /// Close `file` and store its stats in `entry`, possibly setting `file` executable. |
| 279 | /// |
| 280 | /// `desired_bytes` is the amount of bytes Git thinks the file should have after writing. |
| 281 | pub(craterust-analyzer cargo gix-worktree-state 0.30.0 crate/) fn finalize_entryrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/finalize_entry().( |
| 282 | entry: &mut gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::Entryrust-analyzer cargo gix-index 0.51.0 Entry#, |
| 283 | file: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#, |
| 284 | desired_bytes: u64, |
| 285 | #[cfg_attr(windows, allow(unused_variables))] set_executable_after_creation: bool, |
| 286 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), craterust-analyzer cargo gix-worktree-state 0.30.0 crate/::checkoutrust-analyzer cargo gix-worktree-state 0.30.0 checkout/::Errorrust-analyzer cargo gix-worktree-state 0.30.0 checkout/Error#> { |
| 287 | // For possibly existing, overwritten files, we must change the file mode explicitly. |
| 288 | #[cfg(unix)] |
| 289 | if set_executable_after_creation { |
| 290 | set_executablerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/set_executable().(&file)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 291 | } |
| 292 | |
| 293 | let md = &gix_indexrust-analyzer cargo gix-index 0.51.0 crate/::fsrust-analyzer cargo gix-index 0.51.0 fs/::Metadatarust-analyzer cargo gix-index 0.51.0 fs/Metadata#::from_filerust-analyzer cargo gix-index 0.51.0 fs/impl#[Metadata]from_file().(&file)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 294 | // A last sanity check: if the file wasn't truncated upon opening, which is good in case something |
| 295 | // goes wrong during writing, not everything is lost, then after writing the file is smaller than it was |
| 296 | // before, it needs truncation. We do that here. |
| 297 | let needs_truncation = md.lenrust-analyzer cargo gix-index 0.51.0 fs/impl#[Metadata]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().desired_bytes; |
| 298 | if needs_truncation { |
| 299 | file.set_lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]set_len().(desired_bytes)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 300 | } |
| 301 | // NOTE: we don't call `file.sync_all()` here knowing that some filesystems don't handle this well. |
| 302 | // revisit this once there is a bug to fix. |
| 303 | entry.statrust-analyzer cargo gix-index 0.51.0 Entry#stat. = Statrust-analyzer cargo gix-index 0.51.0 entry/Stat#::from_fsrust-analyzer cargo gix-index 0.51.0 entry/stat/impl#[Stat]from_fs().(md)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 304 | file.closerust-analyzer cargo io-close 0.3.7 impl#[`std::fs::File`][Close]close().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 305 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 306 | } |
| 307 | |
| 308 | /// Use `fstat` and `fchmod` on a file descriptor to make a regular file executable. |
| 309 | /// |
| 310 | /// See `let_readers_execute` for the exact details of how the mode is transformed. |
| 311 | #[cfg(unix)] |
| 312 | fn set_executablerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/set_executable().(file: &stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 313 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/::{MetadataExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/MetadataExt#, PermissionsExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/PermissionsExt#}; |
| 314 | let old_mode = file.metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]metadata().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..moderust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/impl#[`fs::Metadata`][MetadataExt]mode().(); |
| 315 | let new_mode = let_readers_executerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/let_readers_execute().(old_mode); |
| 316 | file.set_permissionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]set_permissions().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Permissionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/Permissions#::from_moderust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/impl#[Permissions][PermissionsExt]from_mode().(new_mode))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 317 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 318 | } |
| 319 | |
| 320 | /// Given the st_mode of a regular file, compute the mode with executable bits safely added. |
| 321 | /// |
| 322 | /// Currently this adds executable bits for whoever has read bits already. It doesn't use the umask. |
| 323 | /// Set-user-ID and set-group-ID bits are unset for safety. The sticky bit is also unset. |
| 324 | /// |
| 325 | /// This returns only mode bits, not file type. The return value can be used in chmod or fchmod. |
| 326 | #[cfg(any(unix, test))] |
| 327 | fn let_readers_executerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/let_readers_execute().(mut mode: u32) -> u32 { |
| 328 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(mode &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). 0o170000, 0o100000, "bug in caller if not from a regular file"); |
| 329 | mode rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().&=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().0o777; // Clear type, non-rwx mode bits (setuid, setgid, sticky). |
| 330 | mode rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().(mode rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().0o444) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().2; // Let readers also execute. |
| 331 | mode |
| 332 | } |
| 333 | |
| 334 | #[cfg(test)] |
| 335 | mod testsrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/tests/ { |
| 336 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 337 | fn let_readers_executerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/tests/let_readers_execute().() { |
| 338 | let cases = [ |
| 339 | // Common cases: |
| 340 | (0o100755, 0o755), |
| 341 | (0o100644, 0o755), |
| 342 | (0o100750, 0o750), |
| 343 | (0o100640, 0o750), |
| 344 | (0o100700, 0o700), |
| 345 | (0o100600, 0o700), |
| 346 | (0o100775, 0o775), |
| 347 | (0o100664, 0o775), |
| 348 | (0o100770, 0o770), |
| 349 | (0o100660, 0o770), |
| 350 | (0o100764, 0o775), |
| 351 | (0o100760, 0o770), |
| 352 | // Less common: |
| 353 | (0o100674, 0o775), |
| 354 | (0o100670, 0o770), |
| 355 | (0o100000, 0o000), |
| 356 | (0o100400, 0o500), |
| 357 | (0o100440, 0o550), |
| 358 | (0o100444, 0o555), |
| 359 | (0o100462, 0o572), |
| 360 | (0o100242, 0o252), |
| 361 | (0o100167, 0o177), |
| 362 | // With set-user-ID, set-group-ID, and sticky bits: |
| 363 | (0o104755, 0o755), |
| 364 | (0o104644, 0o755), |
| 365 | (0o102755, 0o755), |
| 366 | (0o102644, 0o755), |
| 367 | (0o101755, 0o755), |
| 368 | (0o101644, 0o755), |
| 369 | (0o106755, 0o755), |
| 370 | (0o106644, 0o755), |
| 371 | (0o104750, 0o750), |
| 372 | (0o104640, 0o750), |
| 373 | (0o102750, 0o750), |
| 374 | (0o102640, 0o750), |
| 375 | (0o101750, 0o750), |
| 376 | (0o101640, 0o750), |
| 377 | (0o106750, 0o750), |
| 378 | (0o106640, 0o750), |
| 379 | (0o107644, 0o755), |
| 380 | (0o107000, 0o000), |
| 381 | (0o106400, 0o500), |
| 382 | (0o102462, 0o572), |
| 383 | ]; |
| 384 | for (st_mode, expected) in cases { |
| 385 | let actual = superrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/::let_readers_executerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/let_readers_execute().(st_mode); |
| 386 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 387 | actual, expected, |
| 388 | "{st_mode:06o} should become {expected:04o}, became {actual:04o}" |
| 389 | ); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 394 | #[should_panic] |
| 395 | fn let_readers_execute_panics_on_directoryrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/tests/let_readers_execute_panics_on_directory().() { |
| 396 | superrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/::let_readers_executerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/let_readers_execute().(0o040644); |
| 397 | } |
| 398 | |
| 399 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 400 | #[should_panic] |
| 401 | fn let_readers_execute_should_panic_on_symlinkrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/tests/let_readers_execute_should_panic_on_symlink().() { |
| 402 | superrust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/::let_readers_executerust-analyzer cargo gix-worktree-state 0.30.0 checkout/entry/let_readers_execute().(0o120644); |
| 403 | } |
| 404 | } |