Skip to content
Permalink
Browse files

FileAttributes: Platform path name conversion

  • Loading branch information
akgrant committed Oct 3, 2018
1 parent bedbadf commit 5c43e10363cb765c8e68eb60665912c6ac330367
Showing with 62 additions and 0 deletions.
  1. +32 −0 src/FileSystem-Tests-Attributes/DiskFileAttributesTests.class.st
  2. +30 −0 src/Files/File.class.st
@@ -123,6 +123,22 @@ DiskFileAttributesTests >> testFileSize [
self collectionAssert: [ :each | each size ] equals: 72.
]

{ #category : #tests }
DiskFileAttributesTests >> testFromPlatformPath [

| testString platformByteArray nativeByteArray |

testString := '1234žřč'.
platformByteArray := {
#Win32 -> #[49 0 50 0 51 0 52 0 126 1 89 1 13 1].
#Win64 -> #[49 0 50 0 51 0 52 0 126 1 89 1 13 1].
#unix -> testString utf8Encoded.
#'Mac OS' -> #[49 50 51 52 122 204 140 114 204 140 99 204 140].
} asDictionary at: OSPlatform current platformName asSymbol.
nativeByteArray := File fromPlatformPath: platformByteArray.
self assert: nativeByteArray utf8Decoded equals: testString.
]

{ #category : #tests }
DiskFileAttributesTests >> testIsBlock [

@@ -266,6 +282,22 @@ DiskFileAttributesTests >> testTargetFile [

]

{ #category : #tests }
DiskFileAttributesTests >> testToPlatformPath [

| testString platformByteArray expectedByteArray |

testString := '1234žřč'.
platformByteArray := File toPlatformPath: testString.
expectedByteArray := {
#Win32 -> #[49 0 50 0 51 0 52 0 126 1 89 1 13 1].
#Win64 -> #[49 0 50 0 51 0 52 0 126 1 89 1 13 1].
#unix -> testString utf8Encoded.
#'Mac OS' -> #[49 50 51 52 122 204 140 114 204 140 99 204 140].
} asDictionary at: OSPlatform current platformName asSymbol.
self assert: platformByteArray equals: expectedByteArray.
]

{ #category : #tests }
DiskFileAttributesTests >> testUidGid [

@@ -312,6 +312,13 @@ File class >> flush: id [
self primitiveFailed
]

{ #category : #attributes }
File class >> fromPlatformPath: aByteArray [
"Convert the supplied platform encoded string to the native (UTF8) equivalent"

^self primFromPlatformPath: aByteArray
]

{ #category : #'primitives-errors' }
File class >> getAttributesFailed [

@@ -734,6 +741,14 @@ File class >> primFileMasks [
^self signalError: error for: 'primFileMasks'
]

{ #category : #'primitives-file attributes' }
File class >> primFromPlatformPath: aByteArray [
"Convert the supplied platform encoded string to the native (UTF8) equivalent"

<primitive: 'primitivePlatToStPath' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: 'primToPlatformPath:'
]

{ #category : #'primitives-windows' }
File class >> primLogicalDrives [
"Answer the windows logical drive mask"
@@ -786,6 +801,14 @@ File class >> primRewinddir: directoryPointerBytes [

]

{ #category : #'primitives-file attributes' }
File class >> primToPlatformPath: aByteArray [
"Convert the supplied UTF8 encoded string to the platform encoded equivalent"

<primitive: 'primitiveStToPlatPath' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: 'primToPlatformPath:'
]

{ #category : #'primitives-file' }
File class >> read: id into: byteArray startingAt: startIndex count: count [
"Read up to count bytes of data from this file into the given string or byte array starting at the given index. Answer the number of bytes actually read."
@@ -1000,6 +1023,13 @@ File class >> timeConversionFailed [
^-5
]

{ #category : #attributes }
File class >> toPlatformPath: aString [
"Convert the supplied string to the platform encoded equivalent"

^self primToPlatformPath: (self encodePathString: aString)
]

{ #category : #'primitives-file' }
File class >> truncate: id to: anInteger [
"Truncate this file to the given position."

0 comments on commit 5c43e10

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