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

Change temporary file creation api #169

Merged
merged 17 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
files
newTemporaryFile
"Create a new temporary file in the systems temp directory and answer its pathString.
It is the users responsibility to delete or move the file, it will not be cleaned up automatically
(unless the host system has a policy for it)."
^ self subclassResponsibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
files
newTemporaryFileNamed: aName
"Create a new temporary file in the systems temp directory and answer its pathString.
It is the users responsibility to delete or move the file, it will not be cleaned up automatically
(unless the host system has a policy for it)."
self subclassResponsibility

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
files
deleteFile: aPathString

GsFile removeServerFile: aPathString
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
files
newTemporaryFile

^ self newTemporaryFileNamed: UUID new greaseString
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
files
newTemporaryFileNamed: aName

| fileName |
fileName := GRPlatform current pathSeparator,'tmp', GRPlatform current pathSeparator, aName.
(self fileExists: fileName) ifTrue: [ GRError new signal: 'A (temporary) file with name ', aName, ' already exists.' ].
^ (GsFile openWriteOnServer: fileName) pathName
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
files
newTemporaryFile

^ self newTemporaryFileNamed: UUID new greaseString
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
files
newTemporaryFileNamed: aName

| newFile |
newFile := FileLocator temp / aName.
newFile exists ifTrue: [ GRError new signal: 'A (temporary) file with name ', aName, ' already exists.' ].
^ newFile pathString
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
It is the users responsibility to delete or move the file,
it will not be cleaned up automatically (unless the host system
has a policy for it)."
self
greaseDeprecatedApi: 'GRPlatform>>newTemporaryFileReference'
details: 'Use newTemporaryFile'.

Check warning on line 10 in repository/Grease-Pharo100-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReference.st

View check run for this annotation

Codecov / codecov/patch

repository/Grease-Pharo100-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReference.st#L8-L10

Added lines #L8 - L10 were not covered by tests
^ self newTemporaryFileReferenceNamed: UUID new asString
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
It is the users responsibility to delete or move the file,
it will not be cleaned up automatically (unless the host system
has a policy for it)."
self
greaseDeprecatedApi: 'GRPlatform>>newTemporaryFileReferenceNamed:'
details: 'Use newTemporaryFileNamed:'.

Check warning on line 10 in repository/Grease-Pharo100-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReferenceNamed..st

View check run for this annotation

Codecov / codecov/patch

repository/Grease-Pharo100-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReferenceNamed..st#L8-L10

Added lines #L8 - L10 were not covered by tests
^ FileLocator temp / aName
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SystemOrganization addCategory: #'Grease-Pharo100-Core'!
self packageOrganizer ensurePackage: #'Grease-Pharo100-Core' withTags: #()!
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
files
newTemporaryFile

^ self newTemporaryFileNamed: UUID new greaseString
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
files
newTemporaryFileNamed: aName

| newFile |
newFile := FileLocator temp / aName.
newFile exists ifTrue: [ GRError new signal: 'A (temporary) file with name ', aName, ' already exists.' ].
^ newFile pathString
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
It is the users responsibility to delete or move the file,
it will not be cleaned up automatically (unless the host system
has a policy for it)."
self
greaseDeprecatedApi: 'GRPlatform>>newTemporaryFileReference'
details: 'Use newTemporaryFile'.

Check warning on line 10 in repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReference.st

View check run for this annotation

Codecov / codecov/patch

repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReference.st#L8-L10

Added lines #L8 - L10 were not covered by tests
^ self newTemporaryFileReferenceNamed: UUID new asString
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
It is the users responsibility to delete or move the file,
it will not be cleaned up automatically (unless the host system
has a policy for it)."
self
greaseDeprecatedApi: 'GRPlatform>>newTemporaryFileReferenceNamed:'
details: 'Use newTemporaryFileNamed:'.

Check warning on line 10 in repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReferenceNamed..st

View check run for this annotation

Codecov / codecov/patch

repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReferenceNamed..st#L8-L10

Added lines #L8 - L10 were not covered by tests
^ FileLocator temp / aName
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
files
newTemporaryFile

^ self newTemporaryFileNamed: UUID new greaseString
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
files
newTemporaryFileNamed: aName

| newFile |
newFile := FileLocator temp / aName.
newFile exists ifTrue: [ GRError new signal: 'A (temporary) file with name ', aName, ' already exists.' ].
^ newFile pathString
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
It is the users responsibility to delete or move the file,
it will not be cleaned up automatically (unless the host system
has a policy for it)."
self
greaseDeprecatedApi: 'GRPlatform>>newTemporaryFileReference'
details: 'Use newTemporaryFile'.

Check warning on line 10 in repository/Grease-Pharo90-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReference.st

View check run for this annotation

Codecov / codecov/patch

repository/Grease-Pharo90-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReference.st#L8-L10

Added lines #L8 - L10 were not covered by tests
^ self newTemporaryFileReferenceNamed: UUID new asString
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
It is the users responsibility to delete or move the file,
it will not be cleaned up automatically (unless the host system
has a policy for it)."
self
greaseDeprecatedApi: 'GRPlatform>>newTemporaryFileReferenceNamed:'
details: 'Use newTemporaryFileNamed:'.

Check warning on line 10 in repository/Grease-Pharo90-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReferenceNamed..st

View check run for this annotation

Codecov / codecov/patch

repository/Grease-Pharo90-Core.package/GRPharoPlatform.class/instance/newTemporaryFileReferenceNamed..st#L8-L10

Added lines #L8 - L10 were not covered by tests
^ FileLocator temp / aName
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
files
deleteFile: aPathString
FileDirectory deleteFilePath: aPathString
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
files
newTemporaryFile

^ self newTemporaryFileNamed: UUID new greaseString
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
files
newTemporaryFileNamed: aName

| file |
file := FileDirectory default / aName.
file exists ifTrue: [ GRError new signal: 'A (temporary) file with name ', aName, ' already exists.' ].
^ file pathName
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
as yet unclassified
files
writeFileStreamOn: aString do: aBlock binary: aBoolean
| stream |
stream := aBoolean
ifTrue: [ (MultiByteFileStream fileNamed: aString) ascii; wantsLineEndConversion: true; yourself ]
ifFalse: [ (FileStream fileNamed: aString) binary ].
ifTrue: [ (FileStream fileNamed: aString) binary ]
ifFalse: [ (MultiByteFileStream fileNamed: aString) ascii; wantsLineEndConversion: true; yourself ].
[ aBlock value: stream ]
ensure: [ stream close ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
files
deleteFile: aPathString
FileDirectory deleteFilePath: aPathString
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
files
newTemporaryFile

^ self newTemporaryFileNamed: UUID new greaseString
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
files
newTemporaryFileNamed: aName

| file |
file := FileDirectory default / aName.
file exists ifTrue: [ GRError new signal: 'A (temporary) file with name ', aName, ' already exists.' ].
^ file pathName
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
files
writeFileStreamOn: aString do: aBlock binary: aBoolean
| stream |
stream := aBoolean
ifTrue: [ (FileStream fileNamed: aString) binary ]
ifFalse: [ (MultiByteFileStream fileNamed: aString) ascii; wantsLineEndConversion: true; yourself ].
[ aBlock value: stream ]
ensure: [ stream close ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
tests-files
testNewTemporaryFile

| temporaryFile1 temporaryFile2 |
[
temporaryFile1 := GRPlatform current newTemporaryFile.
temporaryFile2 := GRPlatform current newTemporaryFile.
GRPlatform current
writeFileStreamOn: temporaryFile1
do: [ :str | str nextPutAll: 'test temporary' ]
binary: false.
GRPlatform current
writeFileStreamOn: temporaryFile2
do: [ :str | str nextPutAll: #[116 101 115 116 32 116 101 109 112 111 114 97 114 121] ]
binary: true.
self assert: (GRPlatform current fileExists: temporaryFile1).
self deny: (GRPlatform current localNameOf: temporaryFile1) equals: (GRPlatform current localNameOf: temporaryFile2)
] ensure: [ GRPlatform current deleteFile: temporaryFile1. GRPlatform current deleteFile: temporaryFile2 ].
self deny: (GRPlatform current fileExists: temporaryFile1).
self deny: (GRPlatform current fileExists: temporaryFile2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests-files
testNewTemporaryFileNamed

| temporaryFile fileName |
fileName := 'GRPlatformTestTemporaryFile'.
[
temporaryFile := GRPlatform current newTemporaryFileNamed: fileName.
GRPlatform current
writeFileStreamOn: temporaryFile
do: [ :str | str nextPutAll: 'test temporary' ]
binary: false.
self assert: (GRPlatform current fileExists: temporaryFile).
self should: [ GRPlatform current newTemporaryFileNamed: fileName ] raise: GRError.
] ensure: [ GRPlatform current deleteFile: temporaryFile ].
self deny: (GRPlatform current fileExists: temporaryFile).

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
tests-files
testWriteToFileInFolder

| bytes text |
bytes := ByteArray new.
self
writeToFile: bytes
withFileNameDo:[ :fileName |
self assert: (GRPlatform current contentsOfFile: fileName binary: true) equals: bytes ].

bytes := #[80 104 39 110 103 108 117 105 32 109 103 108 119 39 110 97 102 104 32 67 116 104 117 108 104 117 32 82 39 108 121 101 104 32 119 103 97 104 39 110 97 103 108 32 102 104 116 97 103 110].
self
writeToFile: bytes
withFileNameDo:[ :fileName |
self assert:(GRPlatform current contentsOfFile: fileName binary: true) equals: bytes ].

text := String new.
self
writeToFile: text
withFileNameDo:[ :fileName |
self assert: (GRPlatform current contentsOfFile: fileName binary: false) equals: text ].

text := 'Ph''nglui mglw''nafh Cthulhu R''lyeh wgah''nagl fhtagn'.
self
writeToFile: text
withFileNameDo:[ :fileName |
self assert: (GRPlatform current contentsOfFile: fileName binary: false) equals: text ]
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SystemOrganization addCategory: #'Grease-Tests-Core'!
self packageOrganizer ensurePackage: #'Grease-Tests-Core' withTags: #()!
Loading