-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
FileSystem.class.st
863 lines (688 loc) · 23.7 KB
/
FileSystem.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
"
I present a low-level protocol for interacting with filesystems. I hold a reference to
a store (a subinstance of FileSystemStore) which takes care of the details of performing
file and directory operations on the filesystem I represent.
I am responsible for resolving all paths that
I pass into my store. My store acts as a factory and offers platform specific actions.
FileSystem instances know two methods that return a Reference object: workingDirectory and root.
FileSystem disk workingDirectory
FileSystem disk root
"
Class {
#name : #FileSystem,
#superclass : #Object,
#instVars : [
'store'
],
#category : #'FileSystem-Core-Public'
}
{ #category : #initializing }
FileSystem class >> startUp: aBoolean [
"This is only here to deal with migration from older versions of
FileSystem that wanted to receive startup notifcations."
SessionManager default unregisterClassNamed: self name
]
{ #category : #'instance creation' }
FileSystem class >> store: aStore [
^ self basicNew
initializeWithStore: aStore;
yourself
]
{ #category : #navigating }
FileSystem >> * anObject [
"Return a relative reference."
^ self referenceTo:( Path * anObject)
]
{ #category : #navigating }
FileSystem >> / anObject [
"Return the absolute reference obtained by resolving anObject against the
root of this filesystem."
^ self root / anObject
]
{ #category : #comparing }
FileSystem >> = other [
^ self species = other species and: [self store = other store]
]
{ #category : #public }
FileSystem >> accessTimeOf: aResolvable [
"Returns the access date of aResolvable"
^ store accessTimeOf: (self resolve: aResolvable)
]
{ #category : #public }
FileSystem >> beReadOnly [
store := store asReadOnlyStore
]
{ #category : #public }
FileSystem >> beWritable [
store := store asWritableStore
]
{ #category : #public }
FileSystem >> binaryReadStreamOn: aResolvable [
"Resolve the argument into an absolute path and open a file handle on the file
at that path. Ask the handle to give us a read stream for reading the file."
^ (self open: aResolvable writable: false) binaryReadStream.
]
{ #category : #public }
FileSystem >> binaryWriteStreamOn: aResolvable [
"Resolve the argument into an absolute path and open a file handle on the file
at that path. Ask the handle to give us a binary write stream for reading the file."
^ (self open: aResolvable writable: true) binaryWriteStream.
]
{ #category : #public }
FileSystem >> changeTimeOf: aResolvable [
"Returns the change time of aResolvable"
^ store changeTimeOf: (self resolve: aResolvable)
]
{ #category : #public }
FileSystem >> checkName: aString fixErrors: fixErrors [
^ store checkName: aString fixErrors: fixErrors
]
{ #category : #'public-enumerating' }
FileSystem >> childNamesAt: aResolvable [
^ Array streamContents: [ :out |
self childNamesAt: aResolvable do: [ :path|
out nextPut: path ]].
]
{ #category : #'public-enumerating' }
FileSystem >> childNamesAt: aResolvable do: aBlock [
| path |
path := self resolve: aResolvable.
store
directoryAt: path
nodesDo: [ :entry |
aBlock value: (store basenameFromEntry: entry) ]
]
{ #category : #'public-enumerating' }
FileSystem >> childrenAt: aResolvable [
^ Array streamContents: [ :out |
self childrenAt: aResolvable do: [ :path|
out nextPut: path ]].
]
{ #category : #'public-enumerating' }
FileSystem >> childrenAt: aResolvable do: aBlock [
| path |
path := self resolve: aResolvable.
store
directoryAt: path
nodesDo: [ :entry |
aBlock value: path / (store basenameFromEntry: entry) ]
]
{ #category : #public }
FileSystem >> close [
store close
]
{ #category : #public }
FileSystem >> copy: sourcePath ifAbsent: absentBlock to: destinationPath ifPresent: presentBlock [
"Copy the file referenced as sourcePath to the destination referred as destPath. Perform associate actions in case of problems."
store
copy: (self resolve: sourcePath)
ifAbsent: absentBlock
to: (self resolve: destinationPath)
ifPresent: presentBlock
fileSystem: self
]
{ #category : #public }
FileSystem >> copy: sourcePath to: destPath [
"Copy the file referenced as sourcePath to the destination referred as destPath.
If there is no file at sourcePath, raise FileDoesNotExist.
If destPath is a file, raise FileExists."
self
copy: sourcePath
ifAbsent: [ store signalFileDoesNotExist: sourcePath ]
to: destPath
ifPresent: [ store signalFileExists: destPath ]
]
{ #category : #public }
FileSystem >> copy: aPath toReference: destinationReference [
^self = destinationReference fileSystem
ifTrue: [ self copy: aPath to: destinationReference resolve path ]
ifFalse: [ self copy: aPath toRemote: destinationReference ]
]
{ #category : #public }
FileSystem >> copy: aPath toRemote: destRef [
| inputStream path |
path := self resolve: aPath.
[ inputStream := self binaryReadStreamOn: path.
inputStream ifNil: [ store signalFileDoesNotExist: path ].
destRef fileSystem copyFrom: inputStream to: destRef path ]
ensure: [ inputStream ifNotNil: [ inputStream close ] ]
]
{ #category : #public }
FileSystem >> copyAndDelete: sourcePath to: destination [
"Copy the file referenced as sourcePath to the destination referred as destPath.
If there is no file at sourcePath, raise FileDoesNotExist.
If destPath is a file, raise FileExists.
If an error occurs during the operation, try and roll back to the original state."
^(self isDirectory: sourcePath) ifTrue:
[ self copyDirectoryAndDelete: sourcePath to: destination ]
ifFalse:
[ self copyFileAndDelete: sourcePath to: destination ].
]
{ #category : #private }
FileSystem >> copyDirectory: sourcePath toReference: destination [
"Copy the source directory to the (yet to be created) destination"
destination createDirectory.
store directoryAt: sourcePath nodesDo:
[ :entry | | basename |
basename := store basenameFromEntry: entry.
(store basicIsDirectory: entry) ifTrue:
[ self copyDirectory: sourcePath / basename toReference: destination / basename ]
ifFalse:
[ self copy: sourcePath / basename toReference: destination / basename ] ]
]
{ #category : #private }
FileSystem >> copyDirectoryAndDelete: sourcePath to: destination [
"Copy the directory sourcePath to the destination referred as destPath.
If destination exists (and is a directory), add sourcePath basename to it,
otherwise create destination as a directory a copy the contents of sourcePath in to it.
If there is no file at sourcePath, raise FileDoesNotExist.
If destPath is a file, raise FileExists.
If an error occurs during the operation, try and roll back to the original state."
"The source must be a directory"
(self isDirectory: sourcePath) ifFalse:
[ (FileException fileName: sourcePath pathString)
message: 'not a directory';
signal ].
"The destination musn't exist yet"
destination ifExists: [ FileAlreadyExistsException signalWith: destination ].
[self copyDirectory: sourcePath toReference: destination]
on: Error
do: [ :error |
destination delete.
error signal].
(FileReference fileSystem: self path: sourcePath) deleteAll.
^destination
]
{ #category : #private }
FileSystem >> copyFileAndDelete: sourcePath to: destination [
"Copy the file referenced as sourcePath to the destination referred as destPath.
If there is no file at sourcePath, raise FileDoesNotExist.
If destPath is a file, raise FileExists.
If an error occurs during the operation, try and roll back to the original state."
[self copy: sourcePath toReference: destination]
on: Error
do: [ :error |
destination ensureDelete.
error signal].
self delete: sourcePath.
^destination
]
{ #category : #private }
FileSystem >> copyFrom: inputStream to: destPath [
| buffer out |
out := nil.
(self exists: destPath)
ifTrue: [ store signalFileExists: destPath ].
^ [
out := self binaryWriteStreamOn: destPath.
buffer := ByteArray new: 1024.
[ inputStream atEnd ]
whileFalse: [
buffer := inputStream nextInto: buffer.
out nextPutAll: buffer ]] ensure: [ out ifNotNil: [ out close ]]
]
{ #category : #public }
FileSystem >> createDirectory: aResolvable [
"Resolve aResolvable into an absolute path, then as the store to create a directory there.
The store is expected to raise an exception if it cannot do so."
^ store createDirectory: (self resolve: aResolvable)
]
{ #category : #public }
FileSystem >> creationTimeOf: aResolvable [
"Returns the creation date of aResolvable"
^ store creationTimeOf: (self resolve: aResolvable)
]
{ #category : #public }
FileSystem >> delete: aResolvable [
store delete: (self resolve: aResolvable)
]
{ #category : #public }
FileSystem >> delimiter [
"Return path delimiter used by this filesystem."
^ store delimiter
]
{ #category : #public }
FileSystem >> deviceIdOf: aResolvable [
"Returns the device id of aResolvable"
^ store deviceIdOf: (self resolve: aResolvable)
]
{ #category : #'public-enumerating' }
FileSystem >> directoriesAt: aResolvable [
^ Array streamContents: [ :out |
self directoriesAt: aResolvable do: [ :path|
out nextPut: path ]].
]
{ #category : #'public-enumerating' }
FileSystem >> directoriesAt: aResolvable do: aBlock [
| path |
path := self resolve: aResolvable.
store
directoryAt: path
directoryNodesDo: [ :entry |
aBlock value: path / (store basenameFromEntry: entry) ]
]
{ #category : #'public-enumerating' }
FileSystem >> directoryNamesAt: aResolvable [
^ Array streamContents: [ :out |
self directoryNamesAt: aResolvable do: [ :name|
out nextPut: name ]].
]
{ #category : #'public-enumerating' }
FileSystem >> directoryNamesAt: aResolvable do: aBlock [
| path |
path := self resolve: aResolvable.
store
directoryAt: path
directoryNodesDo: [ :node |
aBlock value: (store basenameFromEntry: node) ]
]
{ #category : #public }
FileSystem >> ensureCreateDirectory: aResolvable [
"Resolve the argument to an absolute path, then ask the store to make
sure that all the directories contained in the argument path exist or are created."
store ensureCreateDirectory: (self resolve: aResolvable)
]
{ #category : #'public-enumerating' }
FileSystem >> entriesAt: aResolvable [
^ Array
streamContents: [ :out |
self entriesAt: aResolvable do: [ :entry | out nextPut: entry ]
]
]
{ #category : #'public-enumerating' }
FileSystem >> entriesAt: aResolvable do: aBlock [
| path entry |
path := self resolve: aResolvable.
store
directoryAt: path
nodesDo: [ :node |
entry := store entryFromNode: node path: path for: self.
aBlock value: entry ]
]
{ #category : #'public-enumerating' }
FileSystem >> entriesAt: aResolvable ifAbsent: absentBlock do: aBlock [
| path entry aFilesystem |
path := self resolve: aResolvable.
aFilesystem := self.
store
directoryAt: path
ifAbsent: [ ^ absentBlock value ]
nodesDo: [ :node |
entry := store entryFromNode: node path: path for: aFilesystem.
aBlock value: entry ]
]
{ #category : #public }
FileSystem >> entryAt: aResolvable [
"Answer the FileSystemDirectoryEntry for aResolvable"
^ store entryAt: (self resolve: aResolvable) fileSystem: self.
]
{ #category : #public }
FileSystem >> exists: aResolvable [
"Resolve the argument, and answer true if the there is
a file or directory at that path, false if there is not."
^ store exists: (self resolve: aResolvable)
]
{ #category : #public }
FileSystem >> extensionDelimiter [
^ $.
]
{ #category : #public }
FileSystem >> file: aResolvable posixPermissions: anInteger [
"Set the mode of aResolvable to anInteger (as defined by chmod())"
^store file: (self resolve: aResolvable) posixPermissions: anInteger
]
{ #category : #public }
FileSystem >> file: aResolvable symlinkUid: uidInteger gid: gidInteger [
"Set the owner and group of aResolvable by numeric id."
^store file: (self resolve: aResolvable) symlinkUid: uidInteger gid: gidInteger.
]
{ #category : #public }
FileSystem >> file: aResolvable uid: uidInteger gid: gidInteger [
"Set the owner and group of aResolvable by numeric id."
^store file: (self resolve: aResolvable) uid: uidInteger gid: gidInteger.
]
{ #category : #'public-enumerating' }
FileSystem >> fileNamesAt: aResolvable [
^ Array streamContents: [ :out |
self fileNamesAt: aResolvable do: [ :path|
out nextPut: path ]].
]
{ #category : #'public-enumerating' }
FileSystem >> fileNamesAt: aResolvable do: aBlock [
| path |
path := self resolve: aResolvable.
store
directoryAt: path
fileNodesDo: [ :entry |
aBlock value: (store basenameFromEntry: entry) ]
]
{ #category : #'public-enumerating' }
FileSystem >> filesAt: aResolvable [
^ Array streamContents: [ :out |
self filesAt: aResolvable do: [ :path|
out nextPut: path ]].
]
{ #category : #'public-enumerating' }
FileSystem >> filesAt: aResolvable do: aBlock [
| path |
path := self resolve: aResolvable.
store
directoryAt: path
fileNodesDo: [ :entry |
aBlock value: path / (store basenameFromEntry: entry) ]
]
{ #category : #printing }
FileSystem >> forReferencePrintOn: aStream [
store forReferencePrintOn: aStream
]
{ #category : #public }
FileSystem >> gidOf: aResolvable [
"Returns the group id of aResolvable"
^ store gidOf: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> hasChildren: aResolvable [
"Returns whether aResolvable has children."
store directoryAt: (self resolve: aResolvable)
ifAbsent: [ ^false ]
nodesDo: [ :node | ^true ].
^false
]
{ #category : #'public-testing' }
FileSystem >> hasDirectories: aResolvable [
self
entriesAt: aResolvable
ifAbsent: [ ^ false ]
do: [ :entry |
entry isDirectory ifTrue: [ ^true ] ].
^false
]
{ #category : #'public-testing' }
FileSystem >> hasFiles: aResolvable [
self
entriesAt: aResolvable
ifAbsent: [ ^ false ]
do: [ :entry | entry isFile ifTrue: [ ^true ] ].
^false
]
{ #category : #comparing }
FileSystem >> hash [
^ store hash
]
{ #category : #initialization }
FileSystem >> initializeWithStore: aStore [
store := aStore
]
{ #category : #public }
FileSystem >> inodeOf: aResolvable [
"Returns the inode number of aResolvable"
^ store inodeOf: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> isBlock: aResolvable [
"Return a boolean indicating whether the File described by aPath is a block device"
^ store isBlock: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> isCaseSensitive [
^ self store isCaseSensitive
]
{ #category : #'public-testing' }
FileSystem >> isCharacter: aResolvable [
"Return a boolean indicating whether the File described by aPath is character based"
^ store isCharacter: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> isDirectory: aResolvable [
"Resolve the argument, and answer true if the result refers
to a directory, false if it refers to a file or doesn't exist."
^ store isDirectory: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> isExecutable: aResolvable [
"Resolve the argument, and answer true if the there is
a file or directory that can be read from."
^ store isExecutable: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> isFIFO: aResolvable [
"Return a boolean indicating whether the File described by aPath is FIFO"
^ store isFIFO: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> isFile: aResolvable [
"Resolve the argument, and answer true if the result refers
to a file, false if it refers to a directory or doesn't exist."
^ store isFile: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> isHidden: aResolvable attributes: statAttributesArray [
"Resolve the argument, and answer a boolean indicating whether the file is hidden or not.
statAttributesArray is optional and may be supplied for performance. It is the result of File>>fileAttributes:mask: or nil"
^ store isHidden: (self resolve: aResolvable) attributes: statAttributesArray
]
{ #category : #'public-testing' }
FileSystem >> isReadable: aResolvable [
"Resolve the argument, and answer true if the there is
a file or directory that can be read from."
^ store isReadable: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> isRegular: aResolvable [
"Return a boolean indicating whether the File described by aPath is a regular file"
^ store isRegular: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> isSocket: aResolvable [
"Return a boolean indicating whether the File described by aPath is a regular file"
^ store isSocket: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> isSymlink: aResolvable [
"Resolve the argument, and answer true if the result refers
to a directory, false if it refers to a file or doesn't exist."
^ store isSymlink: (self resolve: aResolvable)
]
{ #category : #'public-testing' }
FileSystem >> isWritable [
^ self store isWritable
]
{ #category : #'public-testing' }
FileSystem >> isWritable: aResolvable [
"Resolve the argument, and answer true if the there is
a file that can be written to or directory that can be changed."
^ store isWritable: (self resolve: aResolvable)
]
{ #category : #public }
FileSystem >> modificationTimeOf: aResolvable [
"Returns the last date of modification of aResolvable"
^ store modificationTimeOf: (self resolve: aResolvable)
]
{ #category : #public }
FileSystem >> move: sourcePath to: destination [
"Move the file /directory referenced as sourcePath to the destination referred as destPath.
If there is no file at sourcePath, raise FileDoesNotExist.
If destPath is a file, raise FileExists.
If destPath is a directory, move the sourcePath in to the directory"
| fullDestination destinationPath |
destination isFile ifTrue: [ FileExists signalWith: destination ].
destination isDirectory
ifTrue: [ fullDestination := destination / sourcePath basename ]
ifFalse: [ fullDestination := destination ].
self = destination fileSystem ifTrue:
[
destinationPath := fullDestination resolve path.
sourcePath = destinationPath ifTrue: [ ^fullDestination ].
"Ideally we would test whether the source and destination are on the same filesystem from the OSs perspective.
Since we can't do that, just try rename, and if that fails, copy and delete."
[ self rename: sourcePath to: destinationPath ]
on: Error
do: [ :error | self copyAndDelete: sourcePath to: fullDestination ].
] ifFalse:
[ self copyAndDelete: sourcePath to: fullDestination ].
^fullDestination
]
{ #category : #'public-testing' }
FileSystem >> numberOfHardLinks: aResolvable [
"Resolve the argument, and answer true if the result refers
to a directory, false if it refers to a file or doesn't exist."
^ store numberOfHardLinks: (self resolve: aResolvable)
]
{ #category : #public }
FileSystem >> open [
"Some kinds of filesystems need to open connections to external resources. Does nothing by default."
store open
]
{ #category : #public }
FileSystem >> open: aResolvable writable: aBoolean [
"Resolve aResolvable into an absolute path, then ask the store to open the file at
that path using the specified access mode."
| path |
path := self resolve: aResolvable.
^ store handleClass
open: (FileReference fileSystem: self path: path)
writable: aBoolean
]
{ #category : #private }
FileSystem >> openStreamDescription: aResolvable writable: aBoolean [
"I am a helper method to delegate basicOpen:writable: to the store.
I am called from FileSystemHandle implementations."
| path |
path := self resolve: aResolvable.
^ store basicOpen: path writable: aBoolean
]
{ #category : #converting }
FileSystem >> pathFromObject: anObject [
^ anObject asPathWith: self
]
{ #category : #converting }
FileSystem >> pathFromString: aString [
^ store pathFromString: aString
]
{ #category : #public }
FileSystem >> permissions: aResolvable [
"Resolve the argument and return the Permissions for this file or directory "
^ store permissions: (self resolve: aResolvable)
]
{ #category : #printing }
FileSystem >> printPath: aPath on: aStream [
store printPath: aPath on: aStream
]
{ #category : #public }
FileSystem >> readStreamOn: aResolvable [
"Resolve the argument into an absolute path and open a file handle on the file
at that path. Ask the handle to give us a read stream for reading the file."
^ (self open: aResolvable writable: false) readStream.
]
{ #category : #public }
FileSystem >> referenceTo: aResolvable [
"Answer a reference to the argument from the context of the receiver filesystem.
Example: Filesystem disk referenceTo: 'plonk.taz'"
^ FileReference
fileSystem: self
path: (self pathFromObject: aResolvable)
]
{ #category : #public }
FileSystem >> rename: sourcePath ifAbsent: aBlock to: destPath ifPresent: pBlock [
"Rename the file referenced as sourcePath to the destination referred as destPath.
Perform associate actions in case of problems."
| source destination |
source := self resolve: sourcePath.
destination := self resolve: destPath.
store
rename: source
ifAbsent: aBlock
to: destination
ifPresent: pBlock
fileSystem: self.
^ destination
]
{ #category : #public }
FileSystem >> rename: sourcePath to: destName [
"Rename the file referenced as sourcePath to destPath. Raise exceptions
FileExists or FileDoesNotExist if the operation fails"
^ self
rename: sourcePath
ifAbsent: [store signalFileDoesNotExist: sourcePath]
to: destName
ifPresent: [store signalFileExists: destName]
]
{ #category : #public }
FileSystem >> resolve: aResolvable [
^ aResolvable asResolvedBy: self
]
{ #category : #navigating }
FileSystem >> resolvePath: aPath [
"Return a path where the argument is resolved in the context of the
receiver. The behavior is similar to the one of a command line.
> cd /a/b/c
> cd b
The shell will attempt to make /a/b/c/b the current directory. "
^ self workingDirectoryPath resolve: aPath
]
{ #category : #navigating }
FileSystem >> resolveReference: aReference [
^ aReference fileSystem = self ifTrue:
[self workingDirectoryPath resolvePath: aReference path]
]
{ #category : #navigating }
FileSystem >> resolveString: aString [
"Returns the root of the receiver filesystem, i.e. / on unix"
^ self workingDirectoryPath resolvePath: (store pathFromString: aString)
]
{ #category : #accessing }
FileSystem >> root [
"Returns the root of the receiver filesystem, i.e. / on unix"
^ self referenceTo: Path root
]
{ #category : #accessing }
FileSystem >> separator [
"Return path separator used by this filesystem."
^ store separator
]
{ #category : #public }
FileSystem >> sizeOf: aResolvable [
"Resolve the argument and return the size for this file or directory "
^ store sizeOf: (self resolve: aResolvable)
]
{ #category : #accessing }
FileSystem >> store [
^ store
]
{ #category : #accessing }
FileSystem >> store: aFileSystemStore [
store := aFileSystemStore
]
{ #category : #converting }
FileSystem >> stringFromPath: aPath [
^ store stringFromPath: aPath
]
{ #category : #public }
FileSystem >> symlinkEntryAt: aResolvable [
"Answer the DiskSymlinkDirectoryEntry for aResolvable"
^ store symlinkEntryAt: (self resolve: aResolvable) fileSystem: self.
]
{ #category : #'public-testing' }
FileSystem >> targetPath: aResolvable [
"Return the target file of the File described by aPath. For a regular file, this is itself, for a symbolic link, it is the file pointed to by the symbolic link"
^ store targetPath: (self resolve: aResolvable)
]
{ #category : #public }
FileSystem >> uidOf: aResolvable [
"Returns the user id of aResolvable"
^ store uidOf: (self resolve: aResolvable)
]
{ #category : #accessing }
FileSystem >> workingDirectory [
"Returns a reference to the directory from where the image was launched"
^ self referenceTo: self workingDirectoryPath
]
{ #category : #accessing }
FileSystem >> workingDirectoryPath [
^ store defaultWorkingDirectory
]
{ #category : #public }
FileSystem >> writeStreamOn: aResolvable [
"Open a write stream on the file referred by the argument. It can be a string or a path"
^ (self open: aResolvable writable: true) writeStream.
]