Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#### Unreleased

* BREAKING: Paket no longer looks for projects and `paket.template` files in the folders whose name starts with a dot, like `.devenv`, nor in the folders that are links, as `paket convert-from-nuget` already did for the solutions and NuGet files: the projects there are left out of install, restore, update, remove and pack. Until now only `.git` and `.fable` were skipped. A cyclic link, as in a Nix `.devenv` profile, no longer makes the search run forever - https://github.com/fsprojects/Paket/pull/4421
* The warning about the FSharp.Core binding redirects of F# projects links to an existing section of the documentation

#### 12.0.0-alpha003 - 2026-10-26
Expand Down
14 changes: 9 additions & 5 deletions src/Paket.Core/Common/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,20 @@ let isLink (fileSystemInfo: FileSystemInfo) =
&& fileSystemInfo.Attributes.HasFlag(FileAttributes.ReparsePoint)
&& (try not (isNull fileSystemInfo.LinkTarget) with _ -> true)

/// Gets all files with the given pattern, skipping directories whose name starts with a dot
/// (e.g. .git, .vs, .localhistory) since these are not expected to contain relevant project files
/// and can be large or contain unrelated backup/history data (see issue #3250).
/// The directories that are links are skipped too, as they may lead out of the folder.
/// Whether a search for project related files should not descend into the directory: its name starts
/// with a dot (e.g. .git, .vs, .localhistory, .devenv), so it is not expected to contain relevant files
/// and can be large or contain unrelated backup/history data (see issue #3250), or it is a link,
/// which may lead out of the folder, or back into it on a cycle
let isSkippedSearchDirectory (directory: DirectoryInfo) =
directory.Name.StartsWith "." || isLink directory

/// Gets all files with the given pattern, skipping the directories for which isSkippedSearchDirectory holds
let FindAllFiles(folder, pattern) : FileInfo [] =
let rec allFiles (dir: DirectoryInfo) =
seq {
yield! dir.GetFiles(pattern, SearchOption.TopDirectoryOnly)
for subDir in dir.GetDirectories() do
if not (subDir.Name.StartsWith ".") && not (isLink subDir) then
if not (isSkippedSearchDirectory subDir) then
yield! allFiles subDir
}
allFiles (DirectoryInfo(folder)) |> Seq.toArray
Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/PaketConfigFiles/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,7 @@ type ProjectFile with
member this.FindOrCreateReferencesFile() = ProjectFile.FindOrCreateReferencesFile (FileInfo this.FileName)

// searches directory and all subdirectories for the search pattern, skipping known problematic directories
// and the ones for which isSkippedSearchDirectory holds
static member SearchAllProjectRelatedFiles searchPattern folder : FileInfo [] =
let paketPath = Path.Combine(folder,Constants.PaketFilesFolderName) |> normalizePath

Expand All @@ -1926,9 +1927,8 @@ type ProjectFile with
try
let path = normalizePath di.FullName
if di.Name = Constants.DefaultPackagesFolderName then false else
if di.Name = ".git" then false else
if di.Name = ".fable" then false else
if di.Name = "node_modules" then false else
if isSkippedSearchDirectory di then false else
if topLevel && isLinux && di.FullName = "/sys" then false else
if topLevel && isLinux && di.FullName = "/usr" then false else
if topLevel && isLinux && di.FullName = "/proc" then false else
Expand Down
1 change: 1 addition & 0 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
<Compile Include="ProjectFile\LocalizationSpecs.fs" />
<Compile Include="ProjectFile\UpdateFromNugetSpecs.fs" />
<Compile Include="ProjectFile\ReadPropertySpecs.fs" />
<Compile Include="ProjectFile\FindAllProjectFilesSpecs.fs" />
<Compile Include="ProjectFile\InstallForDotnetSDKSpecs.fs" />
<Compile Include="InstallProcess\FSharpCoreRedirectsWarningSpecs.fs" />
<Compile Include="InstallModel\FrameworkIdentifierSpecs.fs" />
Expand Down
49 changes: 49 additions & 0 deletions tests/Paket.Tests/ProjectFile/FindAllProjectFilesSpecs.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Paket.ProjectFile.FindAllProjectFilesSpecs

open System.IO
open Paket
open NUnit.Framework
open FsUnit

let private findProjects folder =
ProjectFile.FindAllProjectFiles folder |> Array.map (fun fi -> fi.FullName) |> Array.sort

/// Writes an empty project in the folder, creating it, and returns its full path
let private writeProject folder name =
Directory.CreateDirectory(folder) |> ignore
let path = Path.Combine(folder, name)
File.WriteAllText(path, "<Project />")
path

// Regression: a cyclic directory link (e.g. inside a Nix .devenv profile) used to recurse project discovery forever
[<Test>]
[<Timeout 60000>]
let ``FindAllProjectFiles should terminate on a link cycle behind a link``() =
TestHelpers.withTempDir (fun root ->
let outside = Path.Combine(root, "outside")
let search = Path.Combine(root, "search")
writeProject outside "Outside.fsproj" |> ignore
Directory.CreateDirectory(Path.Combine(outside, "sub")) |> ignore
let project = writeProject search "Real.fsproj"
TestHelpers.createDirectoryLinkOrIgnore (Path.Combine(search, "linked")) outside
TestHelpers.createDirectoryLinkOrIgnore (Path.Combine(outside, "sub", "loop")) ".."

findProjects search |> shouldEqual [| project |])

[<Test>]
let ``FindAllProjectFiles should not descend into the folders that are links``() =
TestHelpers.withTempDir (fun root ->
let outside = Path.Combine(root, "outside")
let search = Directory.CreateDirectory(Path.Combine(root, "search")).FullName
writeProject outside "Linked.fsproj" |> ignore
TestHelpers.createDirectoryLinkOrIgnore (Path.Combine(search, "linked")) outside

findProjects search |> shouldEqual [||])

[<Test>]
let ``FindAllProjectFiles should not descend into dot folders``() =
TestHelpers.withTempDir (fun root ->
writeProject (Path.Combine(root, ".devenv")) "Hidden.fsproj" |> ignore
let project = writeProject (Path.Combine(root, "src")) "Visible.fsproj"

findProjects root |> shouldEqual [| project |])
18 changes: 18 additions & 0 deletions tests/Paket.Tests/UtilsSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,24 @@ let ``FindAllFiles should not descend into the folders that are links``() =

files |> shouldEqual [| "root.sln" |])

// Regression: a cyclic directory link (e.g. inside a Nix .devenv profile) must not be followed forever
[<Test>]
[<Timeout 60000>]
let ``FindAllFiles should terminate on a link cycle behind a link``() =
TestHelpers.withTempDir (fun root ->
let outside = Path.Combine(root, "outside")
let repository = Path.Combine(root, "repository")
Directory.CreateDirectory(Path.Combine(outside, "sub")) |> ignore
Directory.CreateDirectory(repository) |> ignore
File.WriteAllText(Path.Combine(outside, "linked.sln"), "")
File.WriteAllText(Path.Combine(repository, "root.sln"), "")
TestHelpers.createDirectoryLinkOrIgnore (Path.Combine(repository, "linked")) outside
TestHelpers.createDirectoryLinkOrIgnore (Path.Combine(outside, "sub", "loop")) ".."

let files = FindAllFiles(repository, "*.sln") |> Array.map (fun fi -> fi.Name)

files |> shouldEqual [| "root.sln" |])

[<Test>]
let ``isDirectoryLink should tell a link given with a trailing separator``() =
TestHelpers.withTempDir (fun root ->
Expand Down
Loading