| | @@ -70,6 +70,12 @@ pub(crate) fn temporary() -> Result<File> { |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | +추가: #[derive(Clone, Copy, Debug)] |
| 74 | +추가: pub(crate) enum Step { |
| 75 | +추가: Check, |
| 76 | +추가: Read { bytes: u64, total: u64 }, |
| 77 | +추가: } |
| 78 | +추가: |
| 73 | 79 | pub(crate) struct Snapshot { |
| 74 | 80 | pub file: File, |
| 75 | 81 | pub len: u64, |
| | @@ -77,7 +83,12 @@ pub(crate) struct Snapshot { |
| 77 | 83 | pub hash: [u8; 32], |
| 78 | 84 | } |
| 79 | 85 | impl Snapshot { |
| 80 | | -삭제: pub fn open(path: &Path, limit: u64, check: &mut impl FnMut() -> Result<()>) -> Result<Self> { |
| 86 | +추가: /// 원본을 임시 파일로 복사하는 동안 읽은 바이트와 전체 크기를 함께 알림. |
| 87 | +추가: pub fn open_reporting( |
| 88 | +추가: path: &Path, |
| 89 | +추가: limit: u64, |
| 90 | +추가: step: &mut impl FnMut(Step) -> Result<()>, |
| 91 | +추가: ) -> Result<Self> { |
| 81 | 92 | let mut options = OpenOptions::new(); |
| 82 | 93 | options.read(true); |
| 83 | 94 | #[cfg(unix)] |
| | @@ -91,7 +102,7 @@ impl Snapshot { |
| 91 | 102 | options.share_mode(1); |
| 92 | 103 | } |
| 93 | 104 | let mut source = options.open(path).map_err(|_| ErrorCode::Io)?; |
| 94 | | -삭제: let snapshot = Self::capture(&mut source, limit, check)?; |
| 105 | +추가: let snapshot = Self::capture_reporting(&mut source, limit, step)?; |
| 95 | 106 | let named = options.open(path).map_err(|_| ErrorCode::SourceChanged)?; |
| 96 | 107 | if filesystem::object(&named)? != snapshot.object |
| 97 | 108 | || !named.metadata().map_err(|_| ErrorCode::Io)?.is_file() |
| | @@ -104,6 +115,16 @@ impl Snapshot { |
| 104 | 115 | source: &mut File, |
| 105 | 116 | limit: u64, |
| 106 | 117 | check: &mut impl FnMut() -> Result<()>, |
| 118 | +추가: ) -> Result<Self> { |
| 119 | +추가: Self::capture_reporting(source, limit, &mut |step| match step { |
| 120 | +추가: Step::Check => check(), |
| 121 | +추가: Step::Read { .. } => Ok(()), |
| 122 | +추가: }) |
| 123 | +추가: } |
| 124 | +추가: fn capture_reporting( |
| 125 | +추가: source: &mut File, |
| 126 | +추가: limit: u64, |
| 127 | +추가: step: &mut impl FnMut(Step) -> Result<()>, |
| 107 | 128 | ) -> Result<Self> { |
| 108 | 129 | let before = source.metadata().map_err(|_| ErrorCode::Io)?; |
| 109 | 130 | if !before.is_file() { |
| | @@ -119,8 +140,10 @@ impl Snapshot { |
| 119 | 140 | let mut buffer = zeroize::Zeroizing::new([0; 65536]); |
| 120 | 141 | let mut hash = Sha256::new(); |
| 121 | 142 | let mut len = 0u64; |
| 143 | +추가: let total = before.len(); |
| 144 | +추가: let mut reported = std::time::Instant::now(); |
| 122 | 145 | loop { |
| 123 | | -삭제: check()?; |
| 146 | +추가: step(Step::Check)?; |
| 124 | 147 | let n = source.read(&mut buffer[..]).map_err(|_| ErrorCode::Io)?; |
| 125 | 148 | if n == 0 { |
| 126 | 149 | break; |
| | @@ -132,7 +155,13 @@ impl Snapshot { |
| 132 | 155 | file.write_all(&buffer[..n]) |
| 133 | 156 | .map_err(crate::space::io_error)?; |
| 134 | 157 | hash.update(&buffer[..n]); |
| 158 | +추가: // 큰 파일에서도 진행이 보이도록 일정 간격으로만 알림. |
| 159 | +추가: if reported.elapsed() >= std::time::Duration::from_millis(200) { |
| 160 | +추가: step(Step::Read { bytes: len, total })?; |
| 161 | +추가: reported = std::time::Instant::now(); |
| 162 | +추가: } |
| 135 | 163 | } |
| 164 | +추가: step(Step::Read { bytes: len, total })?; |
| 136 | 165 | let after = source.metadata().map_err(|_| ErrorCode::Io)?; |
| 137 | 166 | if filesystem::object(&source)? != object |
| 138 | 167 | || before.len() != len |