From 1838e798b146761480c316f374b3c55f93f735d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bouillier?= Date: Mon, 25 Sep 2017 23:41:30 +0200 Subject: [PATCH] Normalize and add Obsolete for Directory module --- src/app/Fake.DotNet.MsBuild/MsBuild.fs | 2 +- src/app/Fake.IO.FileSystem/Directory.fs | 26 +++++-------------- src/app/Fake.IO.FileSystem/Shell.fs | 5 +--- src/app/Fake.Tools.Git/Repository.fs | 2 +- src/app/Fake.Windows.Chocolatey/Chocolatey.fs | 2 +- src/app/FakeLib/FileHelper.fs | 2 ++ src/app/FakeLib/FileSystemHelper.fs | 3 +++ 7 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/app/Fake.DotNet.MsBuild/MsBuild.fs b/src/app/Fake.DotNet.MsBuild/MsBuild.fs index 35d3889edad..77cab3dd98d 100644 --- a/src/app/Fake.DotNet.MsBuild/MsBuild.fs +++ b/src/app/Fake.DotNet.MsBuild/MsBuild.fs @@ -71,7 +71,7 @@ let msBuildExe = /// * just a directory /// if just a directory we can make it the path to a file by Path-Combining the tool name to the directory. let exactPathOrBinaryOnPath tool input = - if Directory.isDirectory input && Directory.Exists input + if Path.isDirectory input && Directory.Exists input then input tool else input diff --git a/src/app/Fake.IO.FileSystem/Directory.fs b/src/app/Fake.IO.FileSystem/Directory.fs index 54e6bfd6954..65a814ea9a4 100644 --- a/src/app/Fake.IO.FileSystem/Directory.fs +++ b/src/app/Fake.IO.FileSystem/Directory.fs @@ -4,20 +4,13 @@ open System.IO module Directory = - /// Creates a directory if it does not exist. - let CreateDir path = - let dir = DirectoryInfo.ofPath path - if not dir.Exists then - // TODO: logfn "Creating %s" dir.FullName - dir.Create() - else () //TODO: logfn "%s already exists." dir.FullName - /// Checks if the given directory exists. If not then this functions creates the directory. let inline ensure dir = - if not (Directory.Exists dir) then - Directory.CreateDirectory dir |> ignore - - let isDirectory path = Path.isDirectory path + dir |> DirectoryInfo.ofPath |> DirectoryInfo.ensure + + /// Creates a directory if it does not exist. + [] + let create = ensure /// Gets the first file in the directory matching the search pattern as an option value. let tryFindFirstMatchingFile pattern dir = @@ -38,12 +31,5 @@ module Directory = let delete path = let dir = DirectoryInfo.ofPath path if dir.Exists then - // set all files readonly = false - DirectoryInfo.setReadOnly false dir - //!!"/**/*.*" - //|> SetBaseDir dir.FullName - //|> (SetReadOnly false) - //logfn "Deleting %s" dir.FullName + DirectoryInfo.setReadOnlyRecursive false dir dir.Delete true - else () //TODO: logfn "%s does not exist." dir.FullName - diff --git a/src/app/Fake.IO.FileSystem/Shell.fs b/src/app/Fake.IO.FileSystem/Shell.fs index dec4d6a652d..47ae562b711 100644 --- a/src/app/Fake.IO.FileSystem/Shell.fs +++ b/src/app/Fake.IO.FileSystem/Shell.fs @@ -182,9 +182,6 @@ module Shell = /// Deletes multiple directories let DeleteDirs dirs = Seq.iter Directory.delete dirs - /// Compat - let ensureDirectory dir = Directory.ensure dir - /// Appends all given files to one file. /// ## Parameters /// @@ -360,7 +357,7 @@ module Shell = else File.Delete f /// Creates a directory if it doesn't exist. - let mkdir path = Directory.CreateDir path + let mkdir path = Directory.create path /// /// Like "cp -r" in a shell. Copies a file or directory recursively. diff --git a/src/app/Fake.Tools.Git/Repository.fs b/src/app/Fake.Tools.Git/Repository.fs index 91794256abc..0f4c757a62b 100644 --- a/src/app/Fake.Tools.Git/Repository.fs +++ b/src/app/Fake.Tools.Git/Repository.fs @@ -67,7 +67,7 @@ let fullclean repositoryDir = Directory.GetDirectories repositoryDir |> Seq.iter deleteDirs else - Directory.CreateDir repositoryDir + Directory.create repositoryDir // set writeable File.SetAttributes(repositoryDir,FileAttributes.Normal) diff --git a/src/app/Fake.Windows.Chocolatey/Chocolatey.fs b/src/app/Fake.Windows.Chocolatey/Chocolatey.fs index 9a5af7d5fef..7919b1f22a6 100644 --- a/src/app/Fake.Windows.Chocolatey/Chocolatey.fs +++ b/src/app/Fake.Windows.Chocolatey/Chocolatey.fs @@ -372,7 +372,7 @@ module Fake.Windows.Choco tempFolder.Create() - Directory.CreateDir (tempFolder.FullName @@ "tools") + Directory.create (tempFolder.FullName @@ "tools") tempFolder.FullName diff --git a/src/app/FakeLib/FileHelper.fs b/src/app/FakeLib/FileHelper.fs index 3d898d74115..a97d6b64bfb 100644 --- a/src/app/FakeLib/FileHelper.fs +++ b/src/app/FakeLib/FileHelper.fs @@ -42,6 +42,7 @@ let SetReadOnly readOnly (files : string seq) = |> setDirectoryReadOnly readOnly) /// Deletes a directory if it exists. +[] let DeleteDir path = let dir = directoryInfo path if dir.Exists then @@ -54,6 +55,7 @@ let DeleteDir path = else logfn "%s does not exist." dir.FullName /// Creates a directory if it does not exist. +[] let CreateDir path = let dir = directoryInfo path if not dir.Exists then diff --git a/src/app/FakeLib/FileSystemHelper.fs b/src/app/FakeLib/FileSystemHelper.fs index 3e86bd09406..ace4ac94bb7 100644 --- a/src/app/FakeLib/FileSystemHelper.fs +++ b/src/app/FakeLib/FileSystemHelper.fs @@ -50,6 +50,7 @@ let filesInDirMatchingRecursive pattern (dir : DirectoryInfo) = else [||] /// Gets the first file in the directory matching the search pattern as an option value. +[] let TryFindFirstMatchingFile pattern dir = dir |> directoryInfo @@ -59,6 +60,7 @@ let TryFindFirstMatchingFile pattern dir = else (Seq.head files).FullName |> Some /// Gets the first file in the directory matching the search pattern or throws an error if nothing was found. +[] let FindFirstMatchingFile pattern dir = match TryFindFirstMatchingFile pattern dir with | Some x -> x @@ -106,6 +108,7 @@ let inline ensureDirExists (dir : DirectoryInfo) = if not dir.Exists then dir.Create() /// Checks if the given directory exists. If not then this functions creates the directory. +[] let inline ensureDirectory dir = directoryInfo dir |> ensureDirExists /// Detects whether the given path is a directory.