Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fake.IO.FileSystem rework #1670

Merged
merged 13 commits into from
Oct 2, 2017

Conversation

devcrafting
Copy link
Contributor

The idea was to add Obsolete documentation at first. I also splitted modules in their own files.

Then I noted that there is an issue of naming/casing consistency accross the FAKE API. Then, I also propose to use a consistent.

For now, I applied the rework only to DirectoryInfo module (given even without the casing changes, there are already some changes in the API). Wait for your feedback before I complete other modules of Fake.IO.FileSystem.

Copy link
Member

@matthid matthid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking care of the cleanup work!
There are some things I have not decided yet, but I think we can release it like this anyway (it probably is a bit more sane than before)

@@ -361,7 +361,7 @@ let tryFindFile dirs file =
|> String.replace "[ProgramFiles]" Environment.ProgramFiles
|> String.replace "[ProgramFilesX86]" Environment.ProgramFilesX86
|> String.replace "[SystemRoot]" Environment.SystemRoot
|> DirectoryInfo.ofPath
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really back and forth about this. We have ofSeq ofList and a lot of these everywhere. But you are right in that this meets the F# Guidelines better :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said on Gitter, I asked people at FableConf, people seems to prefer camelCase for functions.

@@ -0,0 +1,49 @@
namespace Fake.IO.FileSystem
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these modules should move to Fake.IO :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no preferences...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think we should move them (I can do that if you want), because then it is more similar to System.IO and one less open Fake.IO.FileSystem at the top...

module Directory =

/// Creates a directory if it does not exist.
let CreateDir path =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep not yet cleaned all modules, just the DirectoryInfo one.

if not (Directory.Exists dir) then
Directory.CreateDirectory dir |> ignore

let isDirectory path = Path.isDirectory path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directory.isDirectory path reads a bit strange. Though I have no suggestion how to improve. Maybe just leave Directory.Exist and drop this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obsolete to use Path.IsDirectory?

|> DirectoryInfo.OfPath
|> DirectoryInfo.MatchingFiles pattern
|> fun files ->
if Seq.isEmpty files then None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seq.tryHead?

//|> (SetReadOnly false)
//logfn "Deleting %s" dir.FullName
dir.Delete true
else () //TODO: logfn "%s does not exist." dir.FullName
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After all these comments: The Directory module is really not well thought through - for historic reasons. Read my comments not as something you need to fix but as thoughts I'm having when I go through the code...

|> Seq.toList) @ files

/// Copies the file structure recursively.
let CopyRecursiveTo overwrite (outputDir : DirectoryInfo) (dir : DirectoryInfo) = CopyRecursiveToWithFilter overwrite (fun _ _ -> true) outputDir dir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DirectoryInfo module reads a lot better...

@@ -1,304 +0,0 @@
/// Contains helpers which allow to interact with the file system.
namespace Fake.IO.FileSystem
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I don't feel we need to have a separate file for each module (this is not C#).

I'm not against splitting on some defined boundaries, for example we could split out the Operators or File/FileInfo, but as they are quite coupled I don't think that is too viable.

This module is probably one of the hardest to get into a nice state.

@@ -0,0 +1,26 @@
/// NOTE: Maybe this should be an extra module?
/// Contains basic templating functions. Used in other helpers.
module Fake.IO.FileSystem.Templates
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, currently this is quite coupled throughout other modules. I don't like this module ... Kind of broken by design.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But works in practice /shrug

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure something in here makes the build fail on travis... Maybe try to minimize the diff here or revert this change and add changes by hand?

The appveyor failure has something to do with the tests for the legacy FakeLib component. Some behavior was changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep not intended to cmmit this file...I will revert

Copy link
Member

@matthid matthid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really really like it :)

@@ -134,7 +139,7 @@ Target.Create "RenameFSharpCompilerService" (fun _ ->
for framework in ["netstandard1.6"; "net45"] do
let dir = __SOURCE_DIRECTORY__ </> "packages"</>packDir</>"lib"</>framework
let targetFile = dir </> "FAKE.FSharp.Compiler.Service.dll"
File.DeleteFile targetFile
File.Delete targetFile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is System.IO.File.Delete isn't it?
Should we provide delete (ie lower case version) to have unified looking code?

I think there is no easy answer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that's it. I saw System.IO.File is used a lot because some functions in Fake.IO.FileSystem modules are just one line call to BCL...
I will replace it in build.fsx

@@ -120,7 +125,7 @@ Target.Create "Clean" (fun _ ->
//-- "src/*/*/obj/*.props"
//-- "src/*/*/obj/*.paket.references.cached"
//-- "src/*/*/obj/*.NuGet.Config"
|> File.DeleteFiles
|> File.deleteAll
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good choice.

@@ -0,0 +1,49 @@
namespace Fake.IO.FileSystem
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think we should move them (I can do that if you want), because then it is more similar to System.IO and one less open Fake.IO.FileSystem at the top...


open System.IO

module Operators =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we move to Fake.IO I'm not sure how we should call this. Fake.IO.Operators might be too generic. Maybe we leave it in this namespace or call it PathOperators?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change namespace to File.IO. And for Operators, PathOperators seems good ? or FileSystemOperators ? (since we are in Fake.IO.FileSystem package)

@matthid
Copy link
Member

matthid commented Oct 1, 2017

Ok I'm releasing this (Will move move everything to Fake.IO as well)

@matthid matthid merged commit 13a8c33 into fsprojects:master Oct 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants