|
6 | 6 |
|
7 | 7 | use std::collections::BTreeMap; |
8 | 8 | use std::fmt; |
9 | | -use std::fs::{self, Permissions}; |
| 9 | +use std::fs; |
10 | 10 | use std::io::{self, BufRead as _, ErrorKind, Read as _, Write as _, stderr, stdin, stdout}; |
11 | | -use std::os::unix::fs::PermissionsExt as _; |
| 11 | +use std::os::unix::fs::OpenOptionsExt as _; |
12 | 12 | use std::path::{Path, PathBuf}; |
13 | 13 | use std::sync::{Arc, Mutex}; |
14 | 14 | use std::time::{Duration, SystemTime}; |
@@ -154,13 +154,13 @@ impl Cli { |
154 | 154 | } |
155 | 155 | } |
156 | 156 |
|
157 | | -/// Atomically write a file only the user may read. |
| 157 | +/// Atomically write a file only the user may read, born that way |
| 158 | +/// rather than chmodded after opening. |
158 | 159 | fn write_private(path: &Path, bytes: &[u8]) -> io::Result<()> { |
| 160 | + let mut options = fs::OpenOptions::new(); |
| 161 | + options.write(true).create(true).truncate(true).mode(0o600); |
159 | 162 | AtomicFile::new(path, OverwriteBehavior::AllowOverwrite) |
160 | | - .write(|file| { |
161 | | - file.set_permissions(Permissions::from_mode(0o600))?; |
162 | | - file.write_all(bytes) |
163 | | - }) |
| 163 | + .write_with_options(|file| file.write_all(bytes), options) |
164 | 164 | .map_err(|error| match error { |
165 | 165 | atomicwrites::Error::Internal(error) | atomicwrites::Error::User(error) => error, |
166 | 166 | }) |
@@ -282,7 +282,7 @@ impl CommandContext for Cli { |
282 | 282 | created, |
283 | 283 | }) if saved_url == url |
284 | 284 | && saved_fingerprint == fingerprint |
285 | | - && Utc::now() - created < TOKEN_REUSE => |
| 285 | + && (TimeDelta::zero()..TOKEN_REUSE).contains(&(Utc::now() - created)) => |
286 | 286 | { |
287 | 287 | Some(token) |
288 | 288 | } |
|
0 commit comments