Skip to content
This repository was archived by the owner on Jul 28, 2023. It is now read-only.

Commit e40f333

Browse files
authored
Merge pull request #62 from pontem-network/some_fix
Several improvements.
2 parents e3a43b2 + cb52a2c commit e40f333

File tree

5 files changed

+78
-14
lines changed

5 files changed

+78
-14
lines changed

dove/src/cmd/init.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use lang::compiler::dialects::DialectName;
1313
use crate::cmd::Cmd;
1414
use crate::context::{Context, get_context};
1515
use crate::manifest::{DoveToml, MANIFEST};
16+
use lazy_static::lazy_static;
17+
use regex::Regex;
1618

1719
const PONT_STDLIB: &str =
1820
r#"{ git = "https://github.com/pontem-network/move-stdlib", tag = "v0.1.2" }"#;
@@ -88,6 +90,12 @@ impl Cmd for Init {
8890
.and_then(|name| name.to_str())
8991
.ok_or_else(|| anyhow!("Failed to extract directory name."))?;
9092

93+
if !is_valid_name(name) {
94+
return Err(anyhow!(
95+
"Invalid project name. Allowed symbols a-z, A-Z, 0-9,_,-"
96+
));
97+
}
98+
9199
if !self.minimal {
92100
fs::create_dir_all(ctx.path_for(&ctx.manifest.layout.modules_dir))?;
93101
fs::create_dir_all(ctx.path_for(&ctx.manifest.layout.scripts_dir))?;
@@ -131,3 +139,10 @@ dependencies = [
131139
Ok(())
132140
}
133141
}
142+
143+
fn is_valid_name(text: &str) -> bool {
144+
lazy_static! {
145+
static ref RE: Regex = Regex::new(r"^[\w\-_]{1,64}$").unwrap();
146+
}
147+
RE.is_match(text)
148+
}

dove/src/cmd/metadata.rs

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
use std::path::Path;
2+
13
use anyhow::{Error, Result};
24
use serde::Serialize;
35
use structopt::StructOpt;
4-
use std::path::Path;
56

6-
use crate::index::resolver::git;
77
use crate::cmd::Cmd;
88
use crate::context::{Context, str_path};
9-
use crate::manifest::{Dependence, Git, Layout};
9+
use crate::index::resolver::git;
10+
use crate::manifest::{Dependence, Git, Layout, MANIFEST, read_manifest};
1011
use crate::stdoutln;
1112

1213
fn into_metadata(mut ctx: Context) -> Result<DoveMetadata, Error> {
@@ -98,27 +99,67 @@ pub struct GitMetadata {
9899
/// Path.
99100
pub path: Option<String>,
100101
/// Local path.
101-
pub local_path: Option<String>,
102+
pub local_paths: Vec<String>,
102103
}
103104

104105
impl GitMetadata {
105106
/// Create a new git metadata.
106107
pub fn new(git: Git, ctx: &Context) -> Result<GitMetadata, Error> {
107108
let path: &Path = ctx.manifest.layout.deps.as_ref();
108-
let path = ctx.path_for(path.join(&git::make_local_name(&git)));
109-
let local_path = if path.exists() {
110-
Some(str_path(path)?)
111-
} else {
112-
None
113-
};
109+
let pac_path = ctx.path_for(path.join(&git::make_local_name(&git)));
110+
let mut local_paths = Vec::new();
111+
112+
if pac_path.exists() {
113+
let manifest_path = pac_path.join(MANIFEST);
114+
115+
let manifest = if manifest_path.exists() {
116+
match read_manifest(&manifest_path) {
117+
Ok(manifest) => Some(manifest),
118+
Err(err) => {
119+
log::error!("Failed to parse dove manifest:{:?}. Err:{}", pac_path, err);
120+
None
121+
}
122+
}
123+
} else {
124+
None
125+
};
126+
127+
if let Some(manifest) = manifest {
128+
let modules_dir = pac_path.join(manifest.layout.modules_dir);
129+
if modules_dir.exists() {
130+
local_paths.push(str_path(modules_dir)?);
131+
}
132+
if let Some(deps) = manifest.package.dependencies {
133+
for dep in deps.deps.iter() {
134+
if let Dependence::Path(path) = dep {
135+
let local_dep_path = pac_path.join(path.as_ref()).canonicalize();
136+
if let Ok(local_dep_path) = local_dep_path {
137+
if local_dep_path.starts_with(&pac_path) {
138+
local_paths.push(str_path(local_dep_path)?);
139+
continue;
140+
}
141+
}
142+
143+
log::warn!(
144+
"Package '{}' has invalid dependency:{:?}.",
145+
git.git,
146+
path
147+
);
148+
}
149+
}
150+
}
151+
} else {
152+
local_paths.push(str_path(pac_path)?);
153+
}
154+
}
114155

115156
Ok(GitMetadata {
116157
git: git.git,
117158
branch: git.branch,
118159
rev: git.rev,
119160
tag: git.tag,
120161
path: git.path,
121-
local_path,
162+
local_paths,
122163
})
123164
}
124165
}

dove/src/cmd/new.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::cmd::Cmd;
55
use crate::context::{Context, get_context};
66
use crate::cmd::init::Init;
77
use structopt::StructOpt;
8-
use move_core_types::identifier::Identifier;
98
use std::path::PathBuf;
109
use crate::manifest::DoveToml;
1110

@@ -52,8 +51,6 @@ impl Cmd for New {
5251
}
5352

5453
fn apply(self, mut ctx: Context) -> Result<(), Error> {
55-
Identifier::new(self.project_name.as_str())?;
56-
5754
let project_dir = ctx.project_dir.join(&self.project_name);
5855
if project_dir.exists() {
5956
return Err(anyhow!("destination `{:?}` already exists", project_dir));

dove/src/index/resolver/git.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ pub fn resolve(ctx: &Context, git: &Git) -> Result<PathBuf, Error> {
3939
fs::remove_dir_all(&repo_path)?;
4040
return Err(err);
4141
}
42+
43+
if let Err(err) = fs::remove_dir_all(&repo_path.join(".git")) {
44+
warn!("Failed to remove .git in repo {:?}. {}", repo_path, err);
45+
}
46+
4247
if let Some(path_in_repo) = &git.path {
4348
let source_path = repo_path
4449
.join(&path_in_repo)

dove/src/manifest.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ pub struct DepPath {
277277
pub path: String,
278278
}
279279

280+
impl AsRef<str> for DepPath {
281+
fn as_ref(&self) -> &str {
282+
&self.path
283+
}
284+
}
285+
280286
/// Project dependencies.
281287
#[derive(Debug, Clone, PartialEq, Eq, Default)]
282288
pub struct Dependencies {

0 commit comments

Comments
 (0)