Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Sergej Kostjucenko
cargo-contract
Commits
7793ec2a
Unverified
Commit
7793ec2a
authored
May 19, 2022
by
Michael Müller
Committed by
GitHub
May 19, 2022
Browse files
Fix bug when `cargo-contract` installation had been interrupted (#571)
parent
2beb8311
Changes
2
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
7793ec2a
...
...
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-
Updated
`cargo contract new`
template dependencies to ink!
`3`
-
[
#569
](
https://github.com/paritytech/cargo-contract/pull/569
)
-
Improved documentation on how to invoke
`cargo contract decode`
-
[
#572
](
https://github.com/paritytech/cargo-contract/pull/572
)
### Fixed
-
Fix dirty directory issue when crate installation had been interrupted -
[
#571
](
https://github.com/paritytech/cargo-contract/pull/571
)
## [1.3.0] - 2022-05-09
### Added
...
...
build.rs
View file @
7793ec2a
...
...
@@ -106,39 +106,14 @@ fn zip_template_and_build_dylint_driver(
//
// (from https://doc.rust-lang.org/cargo/reference/manifest.html#the-exclude-and-include-fields)
let
original_name
=
ink_dylint_driver_dir
.join
(
"_Cargo.toml"
);
if
!
original_name
.exists
()
{
anyhow
::
bail!
(
"'{:?}' does not exist"
,
original_name
);
}
// After the build process of `ink_linting` happened we need to remove the `Cargo.toml` file.
// Otherwise the directory would be "dirty" and `cargo publish` would fail with `Source
// directory was modified by build.rs during cargo publish`.
let
tmp_name
=
ink_dylint_driver_dir
.join
(
"Cargo.toml"
);
std
::
fs
::
rename
(
&
original_name
,
&
tmp_name
)
.map_err
(|
err
|
{
anyhow
::
anyhow!
(
"Failed renaming '{:?}' to '{:?}': {:?}"
,
original_name
,
tmp_name
,
err
)
})
?
;
let
res
=
build_and_zip_dylint_driver
(
ink_dylint_driver_dir
,
out_dir
,
dylint_driver_dst_file
,
);
// After the build process of `ink_linting` happened we need to name back to the original
// `_Cargo.toml` name, otherwise the directory would be "dirty" and `cargo publish` would
// fail with `Source directory was modified by build.rs during cargo publish`.
std
::
fs
::
rename
(
&
tmp_name
,
&
original_name
)
.map_err
(|
err
|
{
anyhow
::
anyhow!
(
"Failed renaming '{:?}' to '{:?}': {:?}"
,
tmp_name
,
original_name
,
err
)
})
?
;
let
_guard
=
tmp_file_guard
::
FileGuard
::
new
(
original_name
,
tmp_name
);
res
build_and_zip_dylint_driver
(
ink_dylint_driver_dir
,
out_dir
,
dylint_driver_dst_file
)
}
/// Creates a zip archive `template.zip` of the `new` project template in `out_dir`.
...
...
@@ -419,3 +394,36 @@ fn check_dylint_link_installed() -> Result<()> {
}
Ok
(())
}
mod
tmp_file_guard
{
use
std
::
path
::
PathBuf
;
/// Holds the path to a file meant to be temporary.
pub
struct
FileGuard
{
path
:
PathBuf
,
}
impl
FileGuard
{
/// Create a new new file guard.
///
/// Once the object instance is dropped the file will be removed automatically.
pub
fn
new
(
original_name
:
PathBuf
,
tmp_path
:
PathBuf
)
->
Self
{
std
::
fs
::
copy
(
&
original_name
,
&
tmp_path
)
.unwrap_or_else
(|
err
|
{
panic!
(
"Failed copying '{:?}' to '{:?}': {:?}"
,
original_name
,
tmp_path
,
err
)
});
Self
{
path
:
tmp_path
}
}
}
impl
Drop
for
FileGuard
{
// Once the struct instance is dropped we remove the file.
fn
drop
(
&
mut
self
)
{
std
::
fs
::
remove_file
(
&
self
.path
)
.unwrap_or_else
(|
err
|
{
panic!
(
"Failed removing '{:?}': {:?}"
,
self
.path
,
err
)
})
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment