Skip to content

0.7.0-alpha.1: error: failed to move query file when running cargo sqlx prepare #2395

Closed
@aschey

Description

@aschey

This issue appears on the latest commit to main at the time of writing this.

Bug Description

The PR to implement one file per query: #2363 implemented logic to write queries to a temp file and then persist them to SQLX_OFFLINE_DIR here:

let mut tmp_file = tempfile::NamedTempFile::new()
.map_err(|err| format!("failed to create query file: {:?}", err))?;
serde_json::to_writer_pretty(tmp_file.as_file_mut(), self)
.map_err(|err| format!("failed to serialize query data to file: {:?}", err))?;
tmp_file
.persist(dir.as_ref().join(format!("query-{}.json", self.hash)))
.map_err(|err| format!("failed to move query file: {:?}", err))?;

However, the docs for NamedTempFile::persist mention the following:

Note: Temporary files cannot be persisted across filesystems.

On Linux, the /tmp directory is commonly mounted as tmpfs which means the call to tmp_file.persist will result in the following error: failed to move query file: PersistError(Os { code: 18, kind: CrossesDevices, message: "Invalid cross-device link" }).

Perhaps we could use tempfile::NamedTempFile::new_in(dir.as_ref()) to create the temporary files directly in SQLX_OFFLINE_DIR to ensure we're not crossing any filesystem boundaries?

Minimal Reproduction

Run cargo sqlx migrate on a Linux system with /tmp mounted separately from the main OS.

Info

  • SQLx version: 0.7.0-alpha.1
  • SQLx features enabled: "sqlite", "any", "macros", "runtime-tokio"
  • Database server and version: SQLite
  • Operating system: Arch Linux
  • rustc --version: rustc 1.68.0 (2c8cc3432 2023-03-06)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions