89 } |
89 } |
90 |
90 |
91 /// Determines the default hg command. |
91 /// Determines the default hg command. |
92 pub fn default_hg_command() -> OsString { |
92 pub fn default_hg_command() -> OsString { |
93 // TODO: maybe allow embedding the path at compile time (or load from hgrc) |
93 // TODO: maybe allow embedding the path at compile time (or load from hgrc) |
94 env::var_os("CHGHG").or(env::var_os("HG")).unwrap_or(OsStr::new("hg").to_owned()) |
94 env::var_os("CHGHG") |
|
95 .or(env::var_os("HG")) |
|
96 .unwrap_or(OsStr::new("hg").to_owned()) |
95 } |
97 } |
96 |
98 |
97 fn default_timeout() -> Duration { |
99 fn default_timeout() -> Duration { |
98 let secs = env::var("CHGTIMEOUT").ok().and_then(|s| s.parse().ok()).unwrap_or(60); |
100 let secs = env::var("CHGTIMEOUT") |
|
101 .ok() |
|
102 .and_then(|s| s.parse().ok()) |
|
103 .unwrap_or(60); |
99 Duration::from_secs(secs) |
104 Duration::from_secs(secs) |
100 } |
105 } |
101 |
106 |
102 /// Creates a directory which the other users cannot access to. |
107 /// Creates a directory which the other users cannot access to. |
103 /// |
108 /// |
104 /// If the directory already exists, tests its permission. |
109 /// If the directory already exists, tests its permission. |
105 fn create_secure_dir<P>(path: P) -> io::Result<()> |
110 fn create_secure_dir<P>(path: P) -> io::Result<()> |
106 where P: AsRef<Path>, |
111 where |
|
112 P: AsRef<Path>, |
107 { |
113 { |
108 DirBuilder::new().mode(0o700).create(path.as_ref()).or_else(|err| { |
114 DirBuilder::new() |
109 if err.kind() == io::ErrorKind::AlreadyExists { |
115 .mode(0o700) |
110 check_secure_dir(path).map(|_| ()) |
116 .create(path.as_ref()) |
111 } else { |
117 .or_else(|err| { |
112 Err(err) |
118 if err.kind() == io::ErrorKind::AlreadyExists { |
113 } |
119 check_secure_dir(path).map(|_| ()) |
114 }) |
120 } else { |
|
121 Err(err) |
|
122 } |
|
123 }) |
115 } |
124 } |
116 |
125 |
117 fn check_secure_dir<P>(path: P) -> io::Result<P> |
126 fn check_secure_dir<P>(path: P) -> io::Result<P> |
118 where P: AsRef<Path>, |
127 where |
|
128 P: AsRef<Path>, |
119 { |
129 { |
120 let a = fs::symlink_metadata(path.as_ref())?; |
130 let a = fs::symlink_metadata(path.as_ref())?; |
121 if a.is_dir() && a.uid() == procutil::get_effective_uid() && (a.mode() & 0o777) == 0o700 { |
131 if a.is_dir() && a.uid() == procutil::get_effective_uid() && (a.mode() & 0o777) == 0o700 { |
122 Ok(path) |
132 Ok(path) |
123 } else { |
133 } else { |