Skip to content

Commit 8a0772d

Browse files
Address more feedback.
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
1 parent 1f9b048 commit 8a0772d

3 files changed

Lines changed: 23 additions & 12 deletions

File tree

core/src/env/local_directory/metadata.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl Lock {
9090
#[derive(Debug, Deserialize)]
9191
pub struct EnvMetadata {
9292
pub version: String,
93-
#[serde(rename = "project", skip_serializing_if = "Vec::is_empty", default)]
93+
#[serde(rename = "project", default)]
9494
pub projects: Vec<EnvProject>,
9595
}
9696

@@ -176,7 +176,7 @@ impl EnvMetadata {
176176

177177
pub fn add_project(&mut self, project: EnvProject) {
178178
if let Some(found) = self.find_project(&project.identifiers, &project.version) {
179-
self.projects[found].merge(&project);
179+
self.projects[found].merge_identifiers(&project);
180180
} else {
181181
self.projects.push(project);
182182
}
@@ -249,22 +249,22 @@ pub struct EnvProject {
249249
/// identifier, and if the project is not `editable` this
250250
/// is the IRI it is installed as. The rest are considered
251251
/// as aliases. Can only be empty for `editable` projects.
252-
#[serde(skip_serializing_if = "Vec::is_empty", default)]
252+
#[serde(default)]
253253
pub identifiers: Vec<String>,
254254
/// Usages of the project. Intended for tools needing to
255255
/// track the interdependence of project in the environment.
256-
#[serde(skip_serializing_if = "Vec::is_empty", default)]
256+
#[serde(default)]
257257
pub usages: Vec<String>,
258258
/// Indicator of wether the project is fully installed in
259259
/// the environment or located elsewhere.
260-
#[serde(skip_serializing_if = "bool::is_false", default)]
260+
#[serde(default)]
261261
pub editable: bool,
262262
/// In case of an `editable` project these are the files
263263
/// belonging to the project. Intended for tools that
264264
/// are not able to natively parse and understand the
265265
/// projects `.meta.json` file. Paths should be relative
266266
/// to the `path` of the project.
267-
#[serde(skip_serializing_if = "bool::is_false", default)]
267+
#[serde(default)]
268268
pub workspace: bool,
269269
}
270270

@@ -291,17 +291,20 @@ impl EnvProject {
291291
if self.editable {
292292
table.insert("editable", value(true));
293293
}
294+
if self.workspace {
295+
table.insert("workspace", value(true));
296+
}
294297

295298
table
296299
}
297300

298301
/// Adds identifiers from other project.
299302
/// Should only be done if the underlying projects are the same.
300303
/// In particular they must have the same version.
301-
pub fn merge(&mut self, other: &EnvProject) {
304+
pub fn merge_identifiers(&mut self, other: &EnvProject) {
302305
assert_eq!(
303306
self.version, other.version,
304-
"attempting to merge projects with different versions"
307+
"attempting to merge identifiers for projects with different versions"
305308
);
306309

307310
for iri in &other.identifiers {

core/src/project/utils.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,14 @@ pub mod wrapfs {
220220
.map_err(|e| Box::new(FsIoError::WriteFile(path.as_ref().into(), e)))
221221
}
222222

223+
/// Canonicalizes UTF-8 path. If canonicalized path is not valid
224+
/// UTF-8, returns `io::Error` of `InvalidData` kind.
225+
/// On Windows this returns most compatible form of a path instead of UNC.
223226
pub fn canonicalize<P: AsRef<Utf8Path>>(path: P) -> Result<Utf8PathBuf, Box<FsIoError>> {
224227
dunce::canonicalize(path.as_ref())
225-
.map(|path| {
228+
.and_then(|path| {
226229
Utf8PathBuf::from_path_buf(path)
227-
.expect("expected Dunce not to introduce non UTF8 characters")
230+
.map_err(|_| io::Error::from(io::ErrorKind::InvalidData))
228231
})
229232
.map_err(|e| Box::new(FsIoError::Canonicalize(path.as_ref().into(), e)))
230233
}

sysand/src/commands/env.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ use sysand_core::{
1313
commands::{env::do_env_local_dir, lock::LockOutcome},
1414
config::Config,
1515
context::ProjectContext,
16-
env::local_directory::{LocalDirectoryEnvironment, metadata::load_env_metadata},
16+
env::local_directory::{
17+
LocalDirectoryEnvironment,
18+
metadata::{EnvMetadata, load_env_metadata},
19+
},
1720
lock::Lock,
1821
model::InterchangeProjectUsage,
1922
project::{
@@ -36,7 +39,9 @@ use crate::{
3639
};
3740

3841
pub fn command_env<P: AsRef<Utf8Path>>(path: P) -> Result<LocalDirectoryEnvironment> {
39-
Ok(do_env_local_dir(path)?)
42+
let env = do_env_local_dir(path)?;
43+
wrapfs::write(env.metadata_path(), EnvMetadata::default().to_string())?;
44+
Ok(env)
4045
}
4146

4247
// TODO: Factor out provided_iris logic

0 commit comments

Comments
 (0)