Skip to content
Permalink
Browse files

21368: Fix and unify UTF8 file encoding on Windows

  • Loading branch information
akgrant committed Sep 25, 2018
1 parent 86d7b99 commit b4fb3efb4c315f401379b301efdae348436d538f
Showing with 16 additions and 39 deletions.
  1. +2 −2 src/FileSystem-Core/DiskDirectoryEntry.class.st
  2. +3 −3 src/FileSystem-Disk/DiskStore.class.st
  3. +11 −34 src/Files/File.class.st
@@ -129,7 +129,7 @@ DiskDirectoryEntry >> getAllAttributes [
statAttributes := allAttributes at: 1.
accessAttributes := allAttributes at: 2.
(statAttributes at: 1) ifNotNil:
[ statAttributes at: 1 put: (self primitives decode: (statAttributes at: 1)) ].
[ statAttributes at: 1 put: (self primitives decodePathString: (statAttributes at: 1)) ].

]

@@ -139,7 +139,7 @@ DiskDirectoryEntry >> getStatAttributes [

statAttributes := self primitives fileAttributes: self pathString mask: self statAttributeMask.
(statAttributes at: 1) ifNotNil:
[ statAttributes at: 1 put: (self primitives decode: (statAttributes at: 1)) ].
[ statAttributes at: 1 put: (self primitives decodePathString: (statAttributes at: 1)) ].
^statAttributes
]

@@ -448,7 +448,7 @@ DiskStore >> nodesAt: aPath do: aBlock [

| pathString openDir dirPointer entryData fileName attributes targetName |

pathString := File encode: (self stringFromPath: aPath).
pathString := File encodePathString: (self stringFromPath: aPath).
(self isDirectory: aPath) ifFalse:
[ ^self signalDirectoryDoesNotExist: aPath ].

@@ -466,11 +466,11 @@ DiskStore >> nodesAt: aPath do: aBlock [
[ entryData notNil ] whileTrue:
[
fileName := entryData first.
entryData at: 1 put: (File decode: fileName).
entryData at: 1 put: (File decodePathString: fileName).
attributes := entryData at: 2.
attributes ifNotNil:
[ targetName := attributes at: 1.
targetName ifNotNil: [ attributes at: 1 put: (File decode: targetName) ] ].
targetName ifNotNil: [ attributes at: 1 put: (File decodePathString: targetName) ] ].
aBlock value: entryData.
entryData := File primReaddir: dirPointer.
]
@@ -46,7 +46,6 @@ Class {
'name'
],
#classVars : [
'Encoder',
'Registry',
'S_IFBLK',
'S_IFCHR',
@@ -154,16 +153,10 @@ File class >> createDirectory: fullPath [

]

{ #category : #'private-encoding' }
File class >> decode: aString [

^ Encoder decodeBytes: aString asByteArray
]

{ #category : #'primitives-encoding' }
File class >> decodePathString: aString [
File class >> decodePathString: aByteArray [

^ (ZnCharacterEncoder newForEncoding: 'utf8') decodeBytes: aString asByteArray
^ ZnUTF8Encoder default decodeBytes: aByteArray asByteArray
]

{ #category : #'primitives-path' }
@@ -195,31 +188,24 @@ File class >> delimiter [

]

{ #category : #'private-encoding' }
File class >> encode: aString [

^ (Encoder encodeString: aString) asString
]

{ #category : #'primitives-encoding' }
File class >> encodePathString: aString [

"Should not return a string"
^ ((ZnCharacterEncoder newForEncoding: 'utf8') encodeString: aString) asString
^ ZnUTF8Encoder default encodeString: aString
]

{ #category : #testing }
File class >> exists: aString [

^self primExists: (self encode: aString)
^self primExists: (self encodePathString: aString)
]

{ #category : #attributes }
File class >> fileAttribute: aString number: attributeNumber [
"Answer the attribute identified by attributeNumber for the specified file (aString).
For backward compatibility (on Unix) with FileReference if the file doesn't exist, and the specified path is a (broken) symbolic link, answer the requested attribute for the symbolic link."

^self primFileAttribute: (self encode: aString) number: attributeNumber
^self primFileAttribute: (self encodePathString: aString) number: attributeNumber
]

{ #category : #attributes }
@@ -249,7 +235,7 @@ File class >> fileAttributeNumberMap [
{ #category : #attributes }
File class >> fileAttributes: aString mask: attributeMask [

^self primFileAttributes: (self encode: aString) mask: attributeMask
^self primFileAttributes: (self encodePathString: aString) mask: attributeMask
]

{ #category : #'primitives-version' }
@@ -411,8 +397,7 @@ File class >> isSocket: aPath [

{ #category : #'primitives-file modes' }
File class >> isSymlink: aPath [
"Answer a boolean indicating whether the supplied path is a Symlink file.
Note that this should only be called on platforms that support symlinks (e.g. not Windows)"
"Answer a boolean indicating whether the supplied path is a Symlink file"

^self fileAttribute: aPath number: 16
]
@@ -790,10 +775,6 @@ File class >> reset [

| masks |

Encoder := OSPlatform current isWindows
ifTrue: [ ZnCharacterEncoder newForEncoding: 'null' ]
ifFalse: [ ZnCharacterEncoder newForEncoding: 'utf8' ].

masks := self primFileMasks.
S_IFMT := masks at: 1.
S_IFSOCK := masks at: 2.
@@ -879,9 +860,12 @@ File class >> setPosition: id to: anInteger [
]

{ #category : #private }
File class >> signalError: aNumber for: aString [
File class >> signalError: aNumber for: aByteArray [
"Raise the appropriate signal for the supplied error number"

| aString |

aString := self decodePathString: aByteArray.
aNumber = self stringTooLong ifTrue:
[ ^IllegalFileName signalWith: aString ].
aNumber = self cantStatPath ifTrue:
@@ -945,13 +929,6 @@ File class >> stringTooLong [
^-1
]

{ #category : #testing }
File class >> supportsSymbolicLinks [
"Answer a boolean indicating whether the current platform supports symbolic links"

^OSPlatform current isUnix
]

{ #category : #'primitives-file' }
File class >> sync: id [
"On Unix, this syncs any written or flushed data still in the kernel file

0 comments on commit b4fb3ef

Please sign in to comment.
You can’t perform that action at this time.