mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
configs: exit debugdynamicconfig early if .hg isn't writable
Summary: If we're running commands from a user that only has read access, the debugdynamicconfig commands are going to fail. Let's exit early and quickly if that's the case, instead of spending a lot of cpu generating a config only to fail. Reviewed By: quark-zju Differential Revision: D22244127 fbshipit-source-id: 24f806772ba5c08e400efb3abc7ebda228d473a5
This commit is contained in:
parent
b0f4136830
commit
e5a9446057
@ -34,6 +34,7 @@ python27-sys = { version = "0.5", optional = true }
|
|||||||
python3-sys = { version = "0.5", optional = true }
|
python3-sys = { version = "0.5", optional = true }
|
||||||
pytracing = { path = "../../edenscmnative/bindings/modules/pytracing", default-features = false }
|
pytracing = { path = "../../edenscmnative/bindings/modules/pytracing", default-features = false }
|
||||||
revisionstore = { path = "../revisionstore"}
|
revisionstore = { path = "../revisionstore"}
|
||||||
|
tempfile = "3.1"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-collector = { path = "../tracing-collector" }
|
tracing-collector = { path = "../tracing-collector" }
|
||||||
types = { path = "../types" }
|
types = { path = "../types" }
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* GNU General Public License version 2.
|
* GNU General Public License version 2.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{bail, Result};
|
||||||
use clidispatch::{
|
use clidispatch::{
|
||||||
command::{CommandTable, Register},
|
command::{CommandTable, Register},
|
||||||
errors,
|
errors,
|
||||||
@ -14,6 +14,7 @@ use clidispatch::{
|
|||||||
};
|
};
|
||||||
use cliparser::define_flags;
|
use cliparser::define_flags;
|
||||||
use filetime::{set_file_mtime, FileTime};
|
use filetime::{set_file_mtime, FileTime};
|
||||||
|
use tempfile::tempfile_in;
|
||||||
|
|
||||||
use blackbox::{event::Event, json, SessionId};
|
use blackbox::{event::Event, json, SessionId};
|
||||||
use dynamicconfig::Generator;
|
use dynamicconfig::Generator;
|
||||||
@ -297,6 +298,14 @@ pub fn debugdynamicconfig(_opts: NoOpts, _io: &mut IO, repo: Repo) -> Result<u8>
|
|||||||
let repo_name: String = repo
|
let repo_name: String = repo
|
||||||
.repo_name()
|
.repo_name()
|
||||||
.map_or_else(|| "".to_string(), |s| s.to_string());
|
.map_or_else(|| "".to_string(), |s| s.to_string());
|
||||||
|
|
||||||
|
// Verify that the filesystem is writable, otherwise exit early since we won't be able to write
|
||||||
|
// the config.
|
||||||
|
let repo_path = repo.shared_dot_hg_path();
|
||||||
|
if tempfile_in(&repo_path).is_err() {
|
||||||
|
bail!("no write access to {:?}", repo_path);
|
||||||
|
}
|
||||||
|
|
||||||
let config = Generator::new(repo_name, repo.shared_dot_hg_path().to_path_buf())?.execute()?;
|
let config = Generator::new(repo_name, repo.shared_dot_hg_path().to_path_buf())?.execute()?;
|
||||||
let config_str = config.to_string();
|
let config_str = config.to_string();
|
||||||
let config_str = format!(
|
let config_str = format!(
|
||||||
@ -305,7 +314,7 @@ pub fn debugdynamicconfig(_opts: NoOpts, _io: &mut IO, repo: Repo) -> Result<u8>
|
|||||||
config_str
|
config_str
|
||||||
);
|
);
|
||||||
|
|
||||||
let hgrc_path = repo.shared_dot_hg_path().join("hgrc.dynamic");
|
let hgrc_path = repo_path.join("hgrc.dynamic");
|
||||||
|
|
||||||
// If the file exists and will be unchanged, just update the mtime.
|
// If the file exists and will be unchanged, just update the mtime.
|
||||||
if hgrc_path.exists()
|
if hgrc_path.exists()
|
||||||
|
Loading…
Reference in New Issue
Block a user