<commit_before>﻿namespace Paket
open System.IO
open Paket.Domain

[<AutoOpen>]
module CacheExtensions =
    type Nuspec with
        static member LoadFromCache(name:PackageName, version) =
            let getFullPathToNuspec folder = Path.Combine(folder,sprintf "%O.nuspec" name)
            let folder = DirectoryInfo(NuGetCache.GetTargetUserFolder name version).FullName
            let nuspec = getFullPathToNuspec folder
            let fi = FileInfo(nuspec)
            // It happens in some cases that the package is not available in the cache, and in that case
            // it would be sensible to search for the nuspec in the default package folder before returning
            // a Nuspec.All, see issue #3723
            // Maybe this method should be refactored/renamed now, as it not only tries to load from the cache
            // but also the packages folder.
            match fi.Exists with
            | true -> Nuspec.Load nuspec
            | _ -> let nugetPackageFolderPathInDefaultPackageFolder = Path.Combine(Constants.DefaultPackagesFolderName,name.CompareString)
                   let newNuspecPath = getFullPathToNuspec nugetPackageFolderPathInDefaultPackageFolder
                   Nuspec.Load newNuspecPath

    type PackageResolver.PackageInfo with
        member x.Folder root groupName =
            let settings = x.Settings
            let includeVersion = defaultArg settings.IncludeVersionInPath false
            let storageConf = defaultArg settings.StorageConfig PackagesFolderGroupConfig.Default
            match (storageConf.Resolve root groupName x.Name x.Version includeVersion).Path with
            | Some f -> f
            | None ->
                NuGetCache.GetTargetUserFolder x.Name x.Version
<commit_msg>Problem: While paket packing if a dependency is not available in the local user nuget cache, before returning the default Nuspec record, we used to seek the package in the default packages directory, but this method is not fool proof as the dependency might be located within a sub-directory of the default pakcages directory.<commit_after>﻿namespace Paket
open System.IO
open Paket.Domain

[<AutoOpen>]
module CacheExtensions =
    type Nuspec with
        static member LoadFromCache(name:PackageName, version) =
            let folder = DirectoryInfo(NuGetCache.GetTargetUserFolder name version).FullName
            let nuspec = Path.Combine(folder,sprintf "%O.nuspec" name)
            let fi = FileInfo(nuspec)
            // It happens in some cases that the package is not available in the cache, and in that case
            // it would be sensible to recusrively search for the nuspec in the default package folder before returning
            // a Nuspec.All, see issue #3723
            // Maybe this method should be refactored/renamed now, as it not only tries to load from the cache
            // but also the packages folder.
            match fi.Exists with
            | true -> Nuspec.Load nuspec
            | _ -> let candiateNupkgs = Directory.GetFiles(Constants.DefaultPackagesFolderName, sprintf "%O.nuspec" name.CompareString, SearchOption.AllDirectories)
                   let expectedNumberOfMatches = 1
                   if (candiateNupkgs.Length = expectedNumberOfMatches) then Nuspec.Load candiateNupkgs.[0] else Nuspec.Load nuspec

    type PackageResolver.PackageInfo with
        member x.Folder root groupName =
            let settings = x.Settings
            let includeVersion = defaultArg settings.IncludeVersionInPath false
            let storageConf = defaultArg settings.StorageConfig PackagesFolderGroupConfig.Default
            match (storageConf.Resolve root groupName x.Name x.Version includeVersion).Path with
            | Some f -> f
            | None ->
                NuGetCache.GetTargetUserFolder x.Name x.Version

{'fraction_non_alphanumeric': 0.05345501955671447, 'fraction_numerical': 0.002607561929595828, 'mean_word_length': 2.5750232991612303, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3862360', 'n_tokens_mistral': 962, 'n_tokens_neox': 947, 'n_words': 349}