Skip to content

Commit

Permalink
move lock: rewind when creating new lock file from copy (#16444)
Browse files Browse the repository at this point in the history
## Description 

When getting a lock file handle it's useful for it to be set to the beginning for reads rather than the caller needing to rewind it (or forgetting to and not seeing content when reading from the handle).

## Test Plan 

Covered by existing test that exercises these functions together.

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
rvantonder authored Mar 1, 2024
1 parent 8777c4d commit 072f5d9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 1 addition & 2 deletions crates/move-package/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize};
use source_package::{layout::SourcePackageLayout, parsed_manifest::DependencyKind};
use std::{
collections::BTreeMap,
io::{BufRead, Seek, SeekFrom, Write},
io::{BufRead, Write},
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -277,7 +277,6 @@ impl BuildConfig {
};
let install_dir = self.install_dir.as_ref().unwrap_or(path).to_owned();
let mut lock = LockFile::from(install_dir, lock_file)?;
lock.seek(SeekFrom::Start(0))?;
update_compiler_toolchain(
&mut lock,
compiler_version,
Expand Down
3 changes: 2 additions & 1 deletion crates/move-package/src/lock_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::{
fs::{self, File},
io::Write,
io::{Seek, SeekFrom, Write},
ops::{Deref, DerefMut},
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -75,6 +75,7 @@ impl LockFile {
.context("Creating lock file")?;
let lock_string = std::fs::read_to_string(lock_file)?;
lock.write_all(lock_string.as_bytes())?;
lock.seek(SeekFrom::Start(0))?;

Ok(LockFile { file: lock })
}
Expand Down

0 comments on commit 072f5d9

Please sign in to comment.