@@ -7,7 +7,6 @@ use anyhow::{anyhow, bail, Result};
7
7
use pkg:: manifest:: ManifestFile ;
8
8
use std:: collections:: BTreeMap ;
9
9
use std:: fmt;
10
- use std:: fs;
11
10
use std:: path:: Path ;
12
11
use std:: path:: PathBuf ;
13
12
use std:: str:: FromStr ;
@@ -116,30 +115,21 @@ pub fn modify_dependencies(opts: ModifyOpts) -> Result<()> {
116
115
& opts. ipfs_node . clone ( ) . unwrap_or_default ( ) ,
117
116
) ;
118
117
119
- let new_plan = new_plan. or_else ( |e| {
118
+ new_plan. or_else ( |e| {
120
119
std:: fs:: write ( & package_manifest_dir, backup_doc. to_string ( ) )
121
120
. map_err ( |write_err| anyhow ! ( "failed to write toml file: {}" , write_err) ) ?;
122
121
Err ( e)
123
122
} ) ?;
124
123
125
- let new_lock = Lock :: from_graph ( new_plan. graph ( ) ) ;
126
-
127
- new_lock. diff ( & old_lock) ;
128
-
129
124
if opts. dry_run {
130
125
info ! ( "Dry run enabled. toml file not modified." ) ;
131
126
std:: fs:: write ( & package_manifest_dir, backup_doc. to_string ( ) ) ?;
132
- return Ok ( ( ) ) ;
133
- }
134
127
135
- let string = toml:: ser:: to_string_pretty ( & new_lock )
136
- . map_err ( |e| anyhow ! ( "failed to serialize lock file: {}" , e ) ) ?;
128
+ let string = toml:: ser:: to_string_pretty ( & old_lock ) ? ;
129
+ std :: fs :: write ( & lock_path , string ) ?;
137
130
138
- if let Err ( e) = fs:: write ( & lock_path, string) {
139
- std:: fs:: write ( & package_manifest_dir, backup_doc. to_string ( ) )
140
- . map_err ( |e| anyhow ! ( "failed to write toml file: {}" , e) ) ?;
141
- bail ! ( "failed to write lock file: {}" , e) ;
142
- } ;
131
+ return Ok ( ( ) ) ;
132
+ }
143
133
144
134
Ok ( ( ) )
145
135
}
@@ -309,7 +299,13 @@ impl Section {
309
299
dep_data : Dependency ,
310
300
salt : Option < String > ,
311
301
) -> Result < ( ) > {
312
- let mut table = Table :: new ( ) ;
302
+ let section_name = self . to_string ( ) ;
303
+
304
+ if !doc. as_table ( ) . contains_key ( & section_name) {
305
+ doc[ & section_name] = Item :: Table ( Table :: new ( ) ) ;
306
+ }
307
+
308
+ let table = doc[ section_name. as_str ( ) ] . as_table_mut ( ) . unwrap ( ) ;
313
309
314
310
match self {
315
311
Section :: Deps => {
@@ -352,8 +348,6 @@ impl Section {
352
348
}
353
349
} ;
354
350
355
- doc[ & self . to_string ( ) ] = Item :: Table ( table) ;
356
-
357
351
Ok ( ( ) )
358
352
}
359
353
@@ -430,6 +424,7 @@ fn generate_table(details: &DependencyDetails) -> InlineTable {
430
424
mod tests {
431
425
use super :: * ;
432
426
use crate :: WorkspaceManifestFile ;
427
+ use std:: fs;
433
428
use std:: str:: FromStr ;
434
429
use tempfile:: { tempdir, TempDir } ;
435
430
0 commit comments