I have some strong concerns about the semantics of FileSystem on MS Windows treating '\directory' as a relative path rather than an absolute path. For example currently... '/tmp/test.txt' asFileReference fullName --> 'C:\Users\Ben\AppData\Roaming\Pharo\images\30790\tmp\test.txt' when it _should_ go... '/tmp/test.txt' asFileReference fullName --> 'C:\tmp\x.txt' This seems to be by design per '\test\bar' below... WindowsStoreTest>>testAbsolutePath #('c:\' 'C:\temp' 'A:\temp\test') do: [:each | self assert: (WindowsStore current pathFromString: each) isAbsolute ] WindowsStoreTest>>testRelativePath #('a' 'bin\foo' 'temp\test' '\test\bar') do: [:each | self assert: (WindowsStore current pathFromString: each) isRelative ] However taking as reference the Windows Command Shell (cmd.exe)... (1) C:\> mkdir \a\b\a\c (2) C:\> cd a (3) C:\a> cd b (4) C:\a\b> cd \a (5) C:\a> observe that after 'cd \a' (4) the working directory becomes absolute 'C:\a' rather than relative 'C:\a\b\a' . Microsoft defines [1] a file name is RELATIVE to the current directory if it DOES NOT begin with: * A single backslash, for example, "\directory" or "\file.txt". This is also referred to as an ABSOLUTE path. Indeed all Windows applications I know operate this way. Using different semantics is a bug. [1] http://msdn.microsoft.com/en-us/library/aa365247.aspx#fully_qualified_vs._relative_paths What are your thoughts? cheers -ben |
Ben Coman wrote:
> > I have some strong concerns about the semantics of FileSystem on MS > Windows treating '\directory' as a relative path rather than an > absolute path. > > For example currently... > '/tmp/test.txt' asFileReference fullName --> > 'C:\Users\Ben\AppData\Roaming\Pharo\images\30790\tmp\test.txt' > > when it _should_ go... > '/tmp/test.txt' asFileReference fullName --> 'C:\tmp\x.txt' > > This seems to be by design per '\test\bar' below... > > WindowsStoreTest>>testAbsolutePath > #('c:\' 'C:\temp' 'A:\temp\test') do: [:each | > self assert: (WindowsStore current pathFromString: each) > isAbsolute ] > WindowsStoreTest>>testRelativePath > #('a' 'bin\foo' 'temp\test' '\test\bar') do: [:each | > self assert: (WindowsStore current pathFromString: each) > isRelative ] > > However taking as reference the Windows Command Shell (cmd.exe)... > (1) C:\> mkdir \a\b\a\c > (2) C:\> cd a > (3) C:\a> cd b > (4) C:\a\b> cd \a > (5) C:\a> > > observe that after 'cd \a' (4) the working directory becomes absolute > 'C:\a' rather than relative 'C:\a\b\a' . > > Microsoft defines [1] a file name is RELATIVE to the current directory > if it DOES NOT begin with: > * A single backslash, for example, "\directory" or "\file.txt". This > is also referred to as an ABSOLUTE path. > > Indeed all Windows applications I know operate this way. Using > different semantics is a bug. > > [1] > http://msdn.microsoft.com/en-us/library/aa365247.aspx#fully_qualified_vs._relative_paths > > > What are your thoughts? > cheers -ben > > WindowsStoreTest>>testAbsolutePath #('c:\' 'C:\temp' 'A:\temp\test' '\test\bar') do: [:each | "<--MODIFIED" self assert: (WindowsStore current pathFromString: each) isAbsolute ] WindowsStoreTest>>testRelativePath #('a' 'bin\foo' 'temp\test' 'C:temp\test' ) do: [:each | "<--MODIFIED" self assert: (WindowsStore current pathFromString: each) isRelative ] Path>>absoluteWindowsPathRegex ^ (absoluteWindowsPathRegex ifNil: [ absoluteWindowsPathRegex := '([a-zA-Z]\:)?\\.*' asRegex ]) copy "<--MODIFIED" " absoluteWindowsPathRegex := '[a-zA-Z]\:\\.*' asRegex ]) copy" "<--PREVIOUS" Path>>first "<--ADDED" ^ self at: 1. WindowsStore>>printPath: aPath on: aStream (aPath first includes: $:) ifFalse: [ aStream nextPutAll: self currentDisk ; nextPut: self delimiter ]. "<--ADDED" aPath printOn: aStream delimiter: self delimiter WindowsStore>>currentDisk "<--ADDED" "Assumes workingDirectory is always an absolute path" ^ disk ifNil: [ disk = FileSystem workingDirectory path first ] after which... '/tmp/test.txt' asFileReference fullName --> 'C:\tmp\test.txt' This needs some polish. I haven't looked for adverse effects yet. However Pathtest, FileReferenceTest, FileSystemTest & WindowsStoreTest are all green. What do your think? cheers -ben |
[hidden email] wrote:
> Ben Coman wrote: >> >> I have some strong concerns about the semantics of FileSystem on MS >> Windows treating '\directory' as a relative path rather than an >> absolute path. >> >> For example currently... >> '/tmp/test.txt' asFileReference fullName --> >> 'C:\Users\Ben\AppData\Roaming\Pharo\images\30790\tmp\test.txt' >> >> when it _should_ go... >> '/tmp/test.txt' asFileReference fullName --> 'C:\tmp\x.txt' >> >> This seems to be by design per '\test\bar' below... >> >> WindowsStoreTest>>testAbsolutePath >> #('c:\' 'C:\temp' 'A:\temp\test') do: [:each | >> self assert: (WindowsStore current pathFromString: each) >> isAbsolute ] >> WindowsStoreTest>>testRelativePath >> #('a' 'bin\foo' 'temp\test' '\test\bar') do: [:each | >> self assert: (WindowsStore current pathFromString: each) >> isRelative ] >> >> However taking as reference the Windows Command Shell (cmd.exe)... >> (1) C:\> mkdir \a\b\a\c >> (2) C:\> cd a >> (3) C:\a> cd b >> (4) C:\a\b> cd \a >> (5) C:\a> >> >> observe that after 'cd \a' (4) the working directory becomes absolute >> 'C:\a' rather than relative 'C:\a\b\a' . >> >> Microsoft defines [1] a file name is RELATIVE to the current >> directory if it DOES NOT begin with: >> * A single backslash, for example, "\directory" or "\file.txt". This >> is also referred to as an ABSOLUTE path. >> >> Indeed all Windows applications I know operate this way. Using >> different semantics is a bug. >> >> [1] >> http://msdn.microsoft.com/en-us/library/aa365247.aspx#fully_qualified_vs._relative_paths >> >> >> What are your thoughts? >> cheers -ben >> >> > I propose something like the following changes... > > WindowsStoreTest>>testAbsolutePath > #('c:\' 'C:\temp' 'A:\temp\test' '\test\bar') do: [:each | > "<--MODIFIED" > self assert: (WindowsStore current pathFromString: each) > isAbsolute ] > WindowsStoreTest>>testRelativePath > #('a' 'bin\foo' 'temp\test' 'C:temp\test' ) do: [:each | > "<--MODIFIED" > self assert: (WindowsStore current pathFromString: each) > isRelative ] > > Path>>absoluteWindowsPathRegex > ^ (absoluteWindowsPathRegex ifNil: [ > absoluteWindowsPathRegex := '([a-zA-Z]\:)?\\.*' asRegex ]) > copy "<--MODIFIED" " absoluteWindowsPathRegex := > '[a-zA-Z]\:\\.*' asRegex ]) copy" "<--PREVIOUS" > Path>>first "<--ADDED" > ^ self at: 1. > WindowsStore>>printPath: aPath on: aStream > (aPath first includes: $:) ifFalse: [ aStream nextPutAll: self > currentDisk ; nextPut: self delimiter ]. "<--ADDED" > aPath printOn: aStream delimiter: self delimiter > WindowsStore>>currentDisk "<--ADDED" > "Assumes workingDirectory is always an absolute path" > ^ disk ifNil: [ disk = FileSystem workingDirectory path first ] > > after which... > '/tmp/test.txt' asFileReference fullName > --> 'C:\tmp\test.txt' > > This needs some polish. I haven't looked for adverse effects yet. > However Pathtest, FileReferenceTest, FileSystemTest & WindowsStoreTest > are all green. > > What do your think? > cheers -ben > > iterations and is ready for wider testing [1]. Assistance to test and advise if the result is reasonable would be appreciated. [1] https://pharo.fogbugz.com/f/cases/13065/Windows-FileSystem-test-bar-not-an-absolute-path cheers -ben |
Free forum by Nabble | Edit this page |