Skip to content

Commit

Permalink
Normalize and add Obsolete for Directory module
Browse files Browse the repository at this point in the history
  • Loading branch information
devcrafting committed Sep 25, 2017
1 parent 429a520 commit 1838e79
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/app/Fake.DotNet.MsBuild/MsBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 6 additions & 20 deletions src/app/Fake.IO.FileSystem/Directory.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
[<System.Obsolete("Use Directory.ensure instead")>]
let create = ensure

/// Gets the first file in the directory matching the search pattern as an option value.
let tryFindFirstMatchingFile pattern dir =
Expand All @@ -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

5 changes: 1 addition & 4 deletions src/app/Fake.IO.FileSystem/Shell.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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

/// <summary>
/// Like "cp -r" in a shell. Copies a file or directory recursively.
Expand Down
2 changes: 1 addition & 1 deletion src/app/Fake.Tools.Git/Repository.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/app/Fake.Windows.Chocolatey/Chocolatey.fs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ module Fake.Windows.Choco

tempFolder.Create()

Directory.CreateDir (tempFolder.FullName @@ "tools")
Directory.create (tempFolder.FullName @@ "tools")

tempFolder.FullName

Expand Down
2 changes: 2 additions & 0 deletions src/app/FakeLib/FileHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ let SetReadOnly readOnly (files : string seq) =
|> setDirectoryReadOnly readOnly)

/// Deletes a directory if it exists.
[<System.Obsolete("Use Fake.IO.FileSystem instead (FAKE0001 - package: Fake.IO.FileSystem - member: Fake.IO.FileSystem.Directory.delete)")>]
let DeleteDir path =
let dir = directoryInfo path
if dir.Exists then
Expand All @@ -54,6 +55,7 @@ let DeleteDir path =
else logfn "%s does not exist." dir.FullName

/// Creates a directory if it does not exist.
[<System.Obsolete("Use Fake.IO.FileSystem instead (FAKE0001 - package: Fake.IO.FileSystem - member: Fake.IO.FileSystem.Directory.create)")>]
let CreateDir path =
let dir = directoryInfo path
if not dir.Exists then
Expand Down
3 changes: 3 additions & 0 deletions src/app/FakeLib/FileSystemHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
[<Obsolete("Use Fake.IO.FileSystem instead (FAKE0001 - package: Fake.IO.FileSystem - member: Fake.IO.FileSystem.DirectoryInfo.tryFindFirstMatchingFile)")>]
let TryFindFirstMatchingFile pattern dir =
dir
|> directoryInfo
Expand All @@ -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.
[<Obsolete("Use Fake.IO.FileSystem instead (FAKE0001 - package: Fake.IO.FileSystem - member: Fake.IO.FileSystem.DirectoryInfo.findFirstMatchingFile)")>]
let FindFirstMatchingFile pattern dir =
match TryFindFirstMatchingFile pattern dir with
| Some x -> x
Expand Down Expand Up @@ -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.
[<Obsolete("Use Fake.IO.FileSystem instead (FAKE0001 - package: Fake.IO.FileSystem - member: Fake.IO.FileSystem.Directory.ensure)")>]
let inline ensureDirectory dir = directoryInfo dir |> ensureDirExists

/// Detects whether the given path is a directory.
Expand Down

0 comments on commit 1838e79

Please sign in to comment.