Repository: vercel/next.js
File: turbopack/crates/turbo-tasks-fs/src/lib.rs (Rust)

Code before:
            let new_path = std::fs::canonicalize(path)
                .map_err(|_| anyhow!("file is too long, and could not be normalized"))?;
            return Ok(new_path.into());
        }

        Ok(path.into())
    }

    /// Here we are only going to check if the total length exceeds, or the last segment exceeds.
    /// This heuristic is primarily to avoid long file names, and it makes the operation much
    /// cheaper.
    #[cfg(not(windows))]
    fn validate_path_length_inner(path: &Path) -> Result<Cow<'_, Path>> {
        const MAX_FILE_NAME_LENGTH_UNIX: usize = 255;
        // macOS reports a limit of 1024, but I (@arlyon) have had issues with paths above 1016
        // so we subtract a bit to be safe. on most linux distros this is likely a lot larger than
        // 1024, but macOS is *special*
        const MAX_PATH_LENGTH: usize = 1024 - 8;

        // check the last segment (file name)
        if path
            .file_name()
            .map(|n| n.as_encoded_bytes().len())
            .unwrap_or(0)
            > MAX_FILE_NAME_LENGTH_UNIX
        {
            anyhow::bail!(
                "file name is too long (exceeds {} bytes)",
                MAX_FILE_NAME_LENGTH_UNIX,
            );
        }

        if path.as_os_str().len() > MAX_PATH_LENGTH {
            anyhow::bail!("path is too long (exceeds {MAX_PATH_LENGTH} bytes)");
        }

        Ok(path.into())
    }

    validate_path_length_inner(path)
        .with_context(|| format!("path length for file {path:?} exceeds max length of filesystem"))
}

trait ConcurrencyLimitedExt {
    type Output;
    async fn concurrency_limited(self, semaphore: &tokio::sync::Semaphore) -> Self::Output;
}

impl<F, R> ConcurrencyLimitedExt for F
where
    F: Future<Output = R>,

Review comment (suggestion):
<!--__GRAPHITE_HTML_TAG_START__--><p class='graphite__hidden'><i>[Re: line +131]</i></p><!--__GRAPHITE_HTML_TAG_END__-->
super-nit, merge these into two functions with an `if cfg!(windows)` if-statement so both sides are type checked consistently
<!--__GRAPHITE_HTML_TAG_START__--><p class='graphite__hidden'>See this comment inline on <a href="https://app.graphite.com/github/pr/vercel/next.js/88668?utm_source=unchanged-line-comment">Graphite</a>.</p><!--__GRAPHITE_HTML_TAG_END__-->

Code after:
                let new_path = std::fs::canonicalize(path).map_err(|err| {
                    anyhow!(err).context("file is too long, and could not be normalized")
                })?;
                return Ok(new_path.into());
            }

            Ok(path.into())
        } else {
            /// here we are only going to check if the total length exceeds, or the last segment
            /// exceeds. This heuristic is primarily to avoid long file names, and it makes the
            /// operation much cheaper.
            const MAX_FILE_NAME_LENGTH_UNIX: usize = 255;
            // macOS reports a limit of 1024, but I (@arlyon) have had issues with paths above 1016
            // so we subtract a bit to be safe. on most linux distros this is likely a lot larger
            // than 1024, but macOS is *special*
            const MAX_PATH_LENGTH: usize = 1024 - 8;

            // check the last segment (file name)
            if path
                .file_name()
                .map(|n| n.as_encoded_bytes().len())
                .unwrap_or(0)
                > MAX_FILE_NAME_LENGTH_UNIX
            {
                anyhow::bail!(
                    "file name is too long (exceeds {} bytes)",
                    MAX_FILE_NAME_LENGTH_UNIX,
                );
            }

            if path.as_os_str().len() > MAX_PATH_LENGTH {
                anyhow::bail!("path is too long (exceeds {MAX_PATH_LENGTH} bytes)");
            }

            Ok(path.into())
        }
    }

    validate_path_length_inner(path)
        .with_context(|| format!("path length for file {path:?} exceeds max length of filesystem"))
}

trait ConcurrencyLimitedExt {
    type Output;
    async fn concurrency_limited(self, semaphore: &tokio::sync::Semaphore) -> Self::Output;
}

impl<F, R> ConcurrencyLimitedExt for F
where
    F: Future<Output = R>,
{