Skip to content

set_current_dir called with file path instead of directory in find_nearset_pkg_name causes OS error 267 on Windows #402

@GuyFromTheInternet

Description

@GuyFromTheInternet

When using cargo packager -c Packager.toml -f nsis, the CLI fails with:

ERROR I/O Error (\?\D:\project\Packager.toml): The folder name is incorrectly specified. (os error 267)
OS error 267 is ERROR_DIRECTORY on Windows - "The directory name is invalid."

In crates/packager/src/cli/config.rs, the function find_nearset_pkg_name receives a path to the config file but
attempts to use it as a directory:

fn find_nearset_pkg_name(path: &Path) -> Result<Option> {
// ...
let cwd = std::env::current_dir()?;
std::env::set_current_dir(path).map_err(|e| Error::IoWithPath(path.to_path_buf(), e))?; // <-- BUG: path is a
FILE, not a directory
// ...
}

This function is called from parse_config_file at line 99:
let name = find_nearset_pkg_name(path)?;
Where path is the full path to the config file (e.g., D:\project\Packager.toml), not its parent directory.

Suggested Fix:

Change line 56 from:

std::env::set_current_dir(path).map_err(|e| Error::IoWithPath(path.to_path_buf(), e))?;

To:

let dir = path.parent().unwrap_or(Path::new("."));
std::env::set_current_dir(dir).map_err(|e| Error::IoWithPath(dir.to_path_buf(), e))?;

Environment

  • cargo-packager: 0.11.8
  • OS: Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions