This file is indexed.

/usr/share/gnu-smalltalk/kernel/File.st is in gnu-smalltalk-common 3.2.4-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
"======================================================================
|
|   File Method Definitions
|
|
 ======================================================================"

"======================================================================
|
| Copyright 1988,92,94,95,99,2000,2001,2002,2005,2006,2007,2008,2009
| Free Software Foundation, Inc.
| Written by Paolo Bonzini.
|
| This file is part of the GNU Smalltalk class library.
|
| The GNU Smalltalk class library is free software; you can redistribute it
| and/or modify it under the terms of the GNU Lesser General Public License
| as published by the Free Software Foundation; either version 2.1, or (at
| your option) any later version.
| 
| The GNU Smalltalk class library is distributed in the hope that it will be
| useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
| General Public License for more details.
| 
| You should have received a copy of the GNU Lesser General Public License
| along with the GNU Smalltalk class library; see the file COPYING.LIB.
| If not, write to the Free Software Foundation, 59 Temple Place - Suite
| 330, Boston, MA 02110-1301, USA.  
|
 ======================================================================"



FilePath subclass: File [
    | path stat isSymbolicLink |
    
    <category: 'Streams-Files'>
    <comment: 'I enable access to the properties of files that are on disk.'>

    Epoch := nil.

    File class >> initialize [
        "Initialize the receiver's class variables"

        <category: 'initialization'>
        Epoch := DateTime
                    year: 2000
                    day: 1
                    hour: 0
                    minute: 0
                    second: 0
    ]

    File class >> stringError: errno [
	"Answer C strerror's result for errno."
	<category: 'C functions'>
	<cCall: 'strerror' returning: #string args: #(#int)>
	
    ]

    File class >> errno [
	"Answer the current value of C errno."
	<category: 'C functions'>
	<cCall: 'errno' returning: #long args: #()>
	
    ]

    File class >> checkError [
	"Return whether an error had been reported or not.
	 If there had been one, raise an exception too"

	<category: 'file operations'>
	^self checkError: self errno
    ]

    File class >> checkError: errno [
	"The error with the C code `errno' has been reported.
	 If errno >= 1, raise an exception"

	<category: 'file operations'>
	errno < 1 ifTrue: [^false].
	SystemExceptions.FileError signal: (self stringError: errno).
	^true
    ]

    File class >> setTimeFor: fileName atime: atimeSec mtime: mtimeSec [
	<category: 'private-C call-outs'>
	<cCall: 'utime' returning: #int args: #(#string #int #int)>
	
    ]

    File class >> setOwnerFor: fileName owner: ownerString group: groupString [
	<category: 'private-C call-outs'>
	<cCall: 'chown' returning: #int args: #(#string #string #string)>
	
    ]

    File class >> path: aString [
	"Answer a new file with the given path.  The path is not validated until
	 some of the fields of the newly created objects are accessed"

	<category: 'instance creation'>
	^self basicNew init: aString
    ]

    File class >> name: aName [
	"Answer a new file with the given path.  The path is turned into
	 an absolute path."

	<category: 'instance creation'>
	^self path: (self fullNameFor: aName)
    ]

    File class >> touch: fileName [
	"Update the timestamp of the file with the given path name."

	<category: 'file operations'>
	(self path: fileName) touch
    ]

    File class >> symlink: srcName as: destName [
	"Create a symlink for the srcName file with the given path name"

	<category: 'file operations'>
	(self path: srcName) symlinkAs: destName
    ]

    File class >> symlink: destName from: srcName [
	"Create a symlink named destName file from the given path (relative to
	 destName)"

	<category: 'file operations'>
	(self path: destName) symlinkFrom: srcName
    ]

    File class >> remove: fileName [
	"Remove the file with the given path name"

	<category: 'file operations'>
	(self path: fileName) remove
    ]

    File class >> rename: oldFileName to: newFileName [
	"Rename the file with the given path name oldFileName to newFileName"

	<category: 'file operations'>
	(self path: oldFileName) renameTo: newFileName
    ]

    File class >> exists: fileName [
	"Answer whether a file with the given name exists"

	<category: 'testing'>
	^(self path: fileName) exists
    ]

    File class >> isReadable: fileName [
	"Answer whether a file with the given name exists and is readable"

	<category: 'testing'>
	^(self path: fileName) isReadable
    ]

    File class >> isWriteable: fileName [
	"Answer whether a file with the given name exists and is writeable"

	<category: 'testing'>
	^(self path: fileName) isWriteable
    ]

    File class >> isExecutable: fileName [
	"Answer whether a file with the given name exists and can be executed"

	<category: 'testing'>
	^(self path: fileName) isExecutable
    ]

    File class >> isAccessible: fileName [
	"Answer whether a directory with the given name exists and can be accessed"

	<category: 'testing'>
	^(self path: fileName) isAccessible
    ]

    File class >> executable [
	"Answer the full path to the executable being run."

	<category: 'reading system defaults'>
	^self path: ExecutableFileName
    ]

    File class >> image [
	"Answer the full path to the image being used."

	<category: 'reading system defaults'>
	^self path: ImageFileName
    ]

    = aFile [
	"Answer whether the receiver represents the same file as the receiver."

	<category: 'basic'>
	^self class == aFile class and: [ self asString = aFile asString ]
    ]

    hash [
	"Answer a hash value for the receiver."

	<category: 'basic'>
	^self asString hash
    ]

    lstatOn: fileName into: statStruct [
	<category: 'private-C call-outs'>
	<cCall: 'lstat_obj' returning: #int args: #(#string #smalltalk)>
	
    ]

    statOn: fileName into: statStruct [
	<category: 'private-C call-outs'>
	<cCall: 'stat_obj' returning: #int args: #(#string #smalltalk)>
	
    ]

    openDir: dirName [
	<category: 'private-C call-outs'>
	<cCall: 'opendir' returning: #cObject args: #(#string)>
	
    ]

    closeDir: dirObject [
	<category: 'private-C call-outs'>
	<cCall: 'closedir' returning: #int args: #(#cObject)>
	
    ]

    primChmod: name mode: mode [
	<category: 'private-C call-outs'>
	<cCall: 'chmod' returning: #int args: #(#string #int)>
	
    ]

    primIsReadable: name [
	<category: 'private-C call-outs'>
	<cCall: 'fileIsReadable' returning: #boolean args: #(#string)>
	
    ]

    primIsWriteable: name [
	<category: 'private-C call-outs'>
	<cCall: 'fileIsWriteable' returning: #boolean args: #(#string)>
	
    ]

    primIsExecutable: name [
	<category: 'private-C call-outs'>
	<cCall: 'fileIsExecutable' returning: #boolean args: #(#string)>
	
    ]

    primSymlink: srcName as: destName [
	<category: 'private-C call-outs'>
	<cCall: 'symlink' returning: #int args: #(#string #string)>
	
    ]

    primUnlink: fileName [
	<category: 'private-C call-outs'>
	<cCall: 'unlink' returning: #int args: #(#string)>
	
    ]

    primRename: oldFileName to: newFileName [
	<category: 'private-C call-outs'>
	<cCall: 'rename' returning: #int args: #(#string #string)>
	
    ]

    primRemoveDir: fileName [
	<category: 'private-C call-outs'>
	<cCall: 'rmdir' returning: #int args: #(#string)>
	
    ]

    primCreateDir: dirName mode: mode [
	<category: 'private-C call-outs'>
	<cCall: 'mkdir' returning: #int args: #(#string #int)>
	
    ]

    extractDirentName: dirent [
	<category: 'private-C call-outs'>
	<cCall: 'extractDirentName' returning: #string args: #(#cObject)>
	
    ]

    readDir: dirObject [
	<category: 'private-C call-outs'>
	<cCall: 'readdir' returning: #cObject args: #(#cObject)>
	
    ]

    rewindDir: dirObject [
	<category: 'private-C call-outs'>
	<cCall: 'rewinddir' returning: #void args: #(#cObject)>
	
    ]

    , aName [
	"Answer an object of the same kind as the receiver, whose name
	 is suffixed with aName."

	^self class path: self name, aName
    ]

    asString [
	"Answer the name of the file identified by the receiver"

	<category: 'accessing'>
	^path
    ]

    name [
	"Answer the name of the file identified by the receiver"

	<category: 'accessing'>
	^File fullNameFor: self asString
    ]

    size [
	"Answer the size of the file identified by the receiver"

	<category: 'accessing'>
	^self stat stSize
    ]

    mode [
	"Answer the permission bits for the file identified by the receiver"

	<category: 'accessing'>
	^self stat stMode bitAnd: 4095
    ]

    mode: anInteger [
	"Set the permission bits for the file identified by the receiver to be
	 anInteger."

	<category: 'accessing'>
	(self primChmod: self asString mode: (anInteger bitAnd: 4095)) < 0
	    ifTrue: [ File checkError ]
    ]

    isFileSystemPath [
	"Answer whether the receiver corresponds to a real filesystem path."

	<category: 'testing'>
	^true
    ]

    isSocket [
	"Answer whether the file is an AF_UNIX socket."

	<category: 'accessing'>
	self exists ifFalse: [ ^false ].
	^(self stat stMode bitAnd: 8r170000) = 8r140000
    ]

    isDirectory [
	"Answer whether the file is a directory."

	<category: 'accessing'>
	self exists ifFalse: [ ^false ].
	^(self stat stMode bitAnd: 8r170000) = 8r40000
    ]

    isSymbolicLink [
	"Answer whether the file is a symbolic link."

	<category: 'accessing'>
	isSymbolicLink isNil ifTrue: [self refresh].
	^isSymbolicLink
    ]

    lastAccessTime [
	"Answer the last access time of the file identified by the receiver"

	<category: 'accessing'>
	^self getDateAndTime: self stat stAtime
    ]

    lastChangeTime [
	"Answer the last change time of the file identified by the receiver
	 (the `last change time' has to do with permissions, ownership and the
	 like). On some operating systems, this could actually be the
	 file creation time."

	<category: 'accessing'>
	^self getDateAndTime: self stat stCtime
    ]

    creationTime [
	"Answer the creation time of the file identified by the receiver.
	 On some operating systems, this could actually be the last change time
	 (the `last change time' has to do with permissions, ownership and the
	 like)."

	<category: 'accessing'>
	^self getDateAndTime: self stat stCtime
    ]

    lastModifyTime [
	"Answer the last modify time of the file identified by the receiver
	 (the `last modify time' has to do with the actual file contents)."

	<category: 'accessing'>
	^self getDateAndTime: self stat stMtime
    ]

    refresh [
	"Refresh the statistics for the receiver"

	<category: 'accessing'>
	stat isNil ifTrue: [stat := Kernel.Stat new].
	(self lstatOn: self asString into: stat) < 0
            ifTrue: [File checkError].
	isSymbolicLink := (stat stMode bitAnd: 61440) = 40960.	"S_IFLNK"
	isSymbolicLink 
	    ifTrue: 
		[self statOn: self asString into: stat.
		File errno]
    ]

    exists [
	"Answer whether a file with the name contained in the receiver does exist."

	<category: 'testing'>
	stat isNil ifTrue: [stat := Kernel.Stat new].
	(self lstatOn: self asString into: stat) < 0
	    ifTrue: [^false].
	isSymbolicLink := (stat stMode bitAnd: 61440) = 40960.	"S_IFLNK"
	isSymbolicLink ifTrue: [self statOn: self asString into: stat].
	^true
    ]

    isReadable [
	"Answer whether a file with the name contained in the receiver does exist
	 and is readable"

	<category: 'testing'>
	^self primIsReadable: self asString
    ]

    isWriteable [
	"Answer whether a file with the name contained in the receiver does exist
	 and is writeable"

	<category: 'testing'>
	^self primIsWriteable: self asString
    ]

    isAccessible [
	"Answer whether a directory with the name contained in the receiver
	 does exist and is accessible"

	<category: 'testing'>
	^self isDirectory and: [self primIsExecutable: self asString]
    ]

    isExecutable [
	"Answer whether a file with the name contained in the receiver does exist
	 and is executable"

	<category: 'testing'>
	^self isFile and: [self primIsExecutable: self asString]
    ]

    isAbsolute [
	"Answer whether the receiver identifies an absolute path."

	<category: 'testing'>
	^File isAbsolute: self asString
    ]
    
    owner: ownerString group: groupString [
	"Set the receiver's owner and group to be ownerString and groupString."

	<category: 'file operations'>
	(self class 
	    setOwnerFor: self asString
	    owner: ownerString
	    group: groupString) < 0
	        ifTrue: [ File checkError ]
    ]

    lastAccessTime: accessDateTime lastModifyTime: modifyDateTime [
	"Set the receiver's timestamps to be accessDateTime and modifyDateTime."

	<category: 'file operations'>
	(self class 
	    setTimeFor: self asString
	    atime: (self secondsFromDateTime: accessDateTime)
	    mtime: (self secondsFromDateTime: modifyDateTime)) < 0
	        ifTrue: [ File checkError ]
    ]

    open: class mode: mode ifFail: aBlock [
	"Open the receiver in the given mode (as answered by FileStream's
	 class constant methods)"

	<category: 'file operations'>
	^class 
	    fopen: self asString
	    mode: mode
	    ifFail: aBlock
    ]

    remove [
	"Remove the file with the given path name"

	<category: 'file operations'>
        | result |
	result := self isDirectory 
	    ifTrue: [self primRemoveDir: self asString]
	    ifFalse: [self primUnlink: self asString].
	result < 0 ifTrue: [ File checkError ]
    ]

    symlinkFrom: srcName [
	"Create the receiver as a symlink from path destName"

	<category: 'file operations'>
	(self primSymlink: srcName as: self asString) < 0
            ifTrue: [ File checkError ]
    ]

    renameTo: newFileName [
	"Rename the file with the given path name to newFileName"

	<category: 'file operations'>
	(self primRename: self asString to: newFileName) < 0
	    ifTrue: [ File checkError ]
    ]

    secondsFromDateTime: aDateTime [
	"Private - Convert a time expressed in seconds from 1/1/2000 to
	 an array of two Smalltalk Date and Time objects"

	<category: 'private'>
	^aDateTime asSeconds - Epoch asSeconds 
	    - (aDateTime offset asSeconds - Epoch offset asSeconds)
    ]

    getDateAndTime: time [
	"Private - Convert a time expressed in seconds from 1/1/2000 to
	 a Smalltalk DateTime object."

	<category: 'private'>
	^Epoch + (Duration seconds: time) 
	    offset: (Duration seconds: Time timezoneBias)
    ]

    stat [
	"Private - Answer the receiver's statistics' C struct"

	<category: 'private'>
	stat isNil ifTrue: [self refresh].
	^stat
    ]

    createDirectory [
	"Create the receiver as a directory."

	<category: 'directory operations'>
	(self primCreateDir: self asString mode: 8r777) < 0
	    ifTrue: [ File checkError ]
    ]

    namesDo: aBlock [
	"Evaluate aBlock once for each file in the directory represented by the
	 receiver, passing its name. aBlock should not return."

	<category: 'directory operations'>
	| dir entry |
	dir := self openDir: self asString.
	dir isNil ifTrue: [^File checkError].
	
	[[(entry := self readDir: dir) notNil] 
	    whileTrue: [aBlock value: (self extractDirentName: entry)]]
		    ensure: [self closeDir: dir].

	File checkError.
    ]

    symlinkAs: destName [
	"Create destName as a symbolic link of the receiver.  The appropriate
	 relative path is computed automatically."

	<category: 'file operations'>
	| relPath |
	relPath := File pathFrom: destName to: self asString.
	(self class path: destName) symlinkFrom: relPath
    ]

    pathFrom: dir [
	"Compute the relative path from the directory dirName to the receiver"

	<category: 'file operations'>
	^File pathFrom: (dir / 'somefile') asString to: self asString.
    ]

    pathTo: destName [
	"Compute the relative path from the receiver to destName."

	<category: 'accessing'>
	^File pathFrom: (self / 'somefile') asString to: destName asString.
    ]

    full [
	"Answer the full name of the receiver, resolving the `.' and
	 `..' directory entries, and answer the result.  Answer nil if the
	 name is invalid (such as '/usr/../../badname')"

	<category: 'file name management'>
	self isAbsolute ifTrue: [ ^self ].
	^self class path: (File fullNameFor: self name)
    ]

    at: aString [
	"Answer a File or Directory object as appropriate for a file named
	 'aName' in the directory represented by the receiver."

	<category: 'accessing'>
	^self class path: (self nameAt: aString asString)
    ]

    init: aString [
	"Private - Initialize the receiver's instance variables"

	<category: 'private'>
	path := aString
    ]
]


Namespace current: Kernel [

Object subclass: Stat [
    
    | stMode stSize stAtime stMtime stCtime |
    stMode [ ^stMode ]
    stSize [ ^stSize ]
    stAtime [ ^stAtime ]
    stMtime [ ^stMtime ]
    stCtime [ ^stCtime ]
]

]



String extend [
    / aName [
	"Answer a File object as appropriate for a file named
	 'aName' in the directory represented by the receiver."

	<category: 'filesystem'>
	^(File path: self) at: aName
    ]

    asFile [
	"Answer a File object for the file whose name is in the receiver."

	<category: 'filesystem'>
	^(File path: self)
    ]
]

Eval [
    File initialize
]