Skip to content

Commit

Permalink
throw error when creating a duplicate temporary file
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrichau committed Feb 4, 2024
1 parent 22b0950 commit 2816e8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
files
newTemporaryFileNamed: aName

^ (FileLocator temp / aName) pathString
| 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
@@ -1 +1 @@
SystemOrganization addCategory: #'Grease-Pharo100-Core'!
self packageOrganizer ensurePackage: #'Grease-Pharo100-Core' withTags: #()!
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
tests-files
testNewTemporaryFileNamed

| temporaryFile |
| temporaryFile fileName |
fileName := 'GRPlatformTestTemporaryFile'.
[
temporaryFile := GRPlatform current newTemporaryFileNamed: 'test_temporary'.
temporaryFile := GRPlatform current newTemporaryFileNamed: fileName.
GRPlatform current
writeFileStreamOn: temporaryFile
do: [ :str | str nextPutAll: 'test temporary' ]
binary: false.
self assert: (GRPlatform current fileExists: temporaryFile)
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)
self deny: (GRPlatform current fileExists: temporaryFile).

0 comments on commit 2816e8e

Please sign in to comment.