Enhance path handling for init files in ApiService

- Updated logic in `api.rs` to correctly handle cases where existing paths are init files, ensuring that children are placed in the appropriate directory.
- Improved clarity in comments to explain the handling of init files and their relationship to directory structure, contributing to better maintainability of the code.
This commit is contained in:
Joe 2026-02-05 22:05:56 -06:00
parent bc77b26f07
commit f2f5e01a87

View file

@ -869,6 +869,15 @@ impl ApiService {
if !added.children.is_empty() {
let children_dir = if existing_path.is_dir() {
existing_path.to_path_buf()
} else if existing_path
.file_name()
.and_then(|n| n.to_str())
.map_or(false, |n| n.starts_with("init."))
{
// existing_path is an init file (e.g., DirFoo/init.luau).
// The instance is already in directory format -- children go
// into the same directory that contains the init file.
existing_path.parent().unwrap_or(existing_path).to_path_buf()
} else {
// Standalone scripts cannot have children in Rojo's file format.
// We need to convert from standalone (e.g., MyScript.server.luau)