Skip to content

Commit

Permalink
Starting support for long file paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbull committed Aug 22, 2014
1 parent 48f5712 commit bc52adb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/app/FakeLib/FileSystemHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
module Fake.FileSystemHelper

open System
open System.Text
open System.IO
open System.Runtime.InteropServices

module Interop =

[<DllImport("kernel32.dll")>]
extern uint32 GetFullPathName(string lpFileName, uint32 nBufferLength, [<Out>] StringBuilder lpBuffer, [<Out>] StringBuilder lpFilePart);



/// Creates a DirectoryInfo for the given path.
let inline directoryInfo path = new DirectoryInfo(path)
Expand All @@ -19,6 +28,21 @@ let inline fileSystemInfo path : FileSystemInfo =
/// Converts a filename to it's full file system name.
let inline FullName fileName = Path.GetFullPath fileName

///Allows file paths longer than MAX_PATH (260 chars) but has a whole load of caveats
/// see here (http://blogs.msdn.com/b/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx)
let inline FullNameLong fileName =

let getSize fileName =
Interop.GetFullPathName(@"\\?\" + fileName, 1u, new StringBuilder(1), new StringBuilder(1))

let size = (getSize fileName) + 10u

let fullPath = new StringBuilder(size |> int)
let fname = new StringBuilder(size |> int)
ignore(Interop.GetFullPathName(@"\\?\" + fileName, size, fullPath, fname))

fullPath.ToString()

/// Gets the directory part of a filename.
let inline DirectoryName fileName = Path.GetDirectoryName fileName

Expand Down

2 comments on commit bc52adb

@colinbull
Copy link
Owner Author

Choose a reason for hiding this comment

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

@forki I have added a FullNameLong function in this commit (untested) re. fsprojects#167. But do you think this should be the default behaviour? I'm in two minds because of this series of posts

@forki
Copy link

@forki forki commented on bc52adb Mar 12, 2015

Choose a reason for hiding this comment

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

will it break our "normal" stuff?

Please sign in to comment.