The Trunk: Files-pre.182.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Files-pre.182.mcz

commits-2
Patrick Rein uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-pre.182.mcz

==================== Summary ====================

Name: Files-pre.182
Author: pre
Time: 11 December 2018, 3:28:52.883299 pm
UUID: 093bb32f-7338-44b8-a2b7-250c5d9c0956
Ancestors: Files-nice.163, Files-tpr.181

Recategorizes methods in the files package. Also moves a deprecated method into the corresponding deprecated extension category.

=============== Diff against Files-tpr.181 ===============

Item was changed:
+ ----- Method: AsyncFile>>close (in category 'file open/close') -----
- ----- Method: AsyncFile>>close (in category 'as yet unclassified') -----
  close
 
  fileHandle ifNil: [^ self].  "already closed"
  self primClose: fileHandle.
  Smalltalk unregisterExternalObject: semaphore.
  semaphore := nil.
  fileHandle := nil.
  !

Item was changed:
+ ----- Method: AsyncFile>>fileHandle (in category 'accessing') -----
- ----- Method: AsyncFile>>fileHandle (in category 'as yet unclassified') -----
  fileHandle
  ^ fileHandle!

Item was changed:
+ ----- Method: AsyncFile>>open:forWrite: (in category 'file open/close') -----
- ----- Method: AsyncFile>>open:forWrite: (in category 'as yet unclassified') -----
  open: fullFileName forWrite: aBoolean
  "Open a file of the given name, and return a handle for that file. Answer the receiver if the primitive succeeds, nil otherwise.
  If openForWrite is true, then:
  if there is no existing file with this name, then create one
  else open the existing file in read-write mode
  otherwise:
  if there is an existing file with this name, then open it read-only
  else answer nil."
  "Note: if an exisiting file is opened for writing, it is NOT truncated. If truncation is desired, the file should be deleted before being opened as an asynchronous file."
  "Note: On some platforms (e.g., Mac), a file can only have one writer at a time."
 
  name := fullFileName.
  writeable := aBoolean.
  ^Smalltalk newExternalSemaphoreDo: [ :newSemaphore :index |
  fileHandle := self primOpen: name asVmPathName forWrite: writeable semaIndex: index.
  fileHandle
  ifNotNil: [
  semaphore := newSemaphore.
  self ]
  ifNil: [
  Smalltalk unregisterExternalObject: newSemaphore.
  nil ] ]!

Item was changed:
+ ----- Method: AsyncFile>>readByteCount:fromFilePosition:onCompletionDo: (in category 'reading') -----
- ----- Method: AsyncFile>>readByteCount:fromFilePosition:onCompletionDo: (in category 'as yet unclassified') -----
  readByteCount: byteCount fromFilePosition: fPosition onCompletionDo: aBlock
  "Start a read operation to read byteCount's from the given position in this file. and fork a process to await its completion. When the operation completes, evaluate the given block. Note that, since the completion block may run asynchronous, the client may need to use a SharedQueue or a semaphore for synchronization."
 
  | buffer |
  buffer := String new: byteCount.
  self primReadStart: fileHandle fPosition: fPosition count: byteCount.
  "here's the process that awaits the results:"
  [| n |
  [ semaphore wait.
    n := self primReadResult: fileHandle intoBuffer: buffer at: 1 count: byteCount.
    n = Busy.
  ] whileTrue.  "loop while busy in case the semaphore had excess signals"
  n = ErrorCode ifTrue: [^ self error: 'asynchronous read operation failed'].
  aBlock value: buffer.
  ] forkAt: Processor userInterruptPriority.
  !

Item was changed:
+ ----- Method: AsyncFile>>test:fileName: (in category 'tests') -----
- ----- Method: AsyncFile>>test:fileName: (in category 'as yet unclassified') -----
  test: byteCount fileName: fileName
  "AsyncFile new test: 10000 fileName: 'testData'"
 
  | buf1 buf2 bytesWritten bytesRead |
  buf1 := String new: byteCount withAll: $x.
  buf2 := String new: byteCount.
  self open: ( FileDirectory default fullNameFor: fileName) forWrite: true.
  self primWriteStart: fileHandle
  fPosition: 0
  fromBuffer: buf1
  at: 1
  count: byteCount.
  semaphore wait.
  bytesWritten := self primWriteResult: fileHandle.
  self close.
 
  self open: ( FileDirectory default fullNameFor: fileName) forWrite: false.
  self primReadStart: fileHandle fPosition: 0 count: byteCount.
  semaphore wait.
  bytesRead :=
  self primReadResult: fileHandle
  intoBuffer: buf2
  at: 1
  count: byteCount.
  self close.
 
  buf1 = buf2 ifFalse: [self error: 'buffers do not match'].
  ^ 'wrote ', bytesWritten printString, ' bytes; ',
    'read ', bytesRead printString, ' bytes'
  !

Item was changed:
+ ----- Method: AsyncFile>>waitForCompletion (in category 'private') -----
- ----- Method: AsyncFile>>waitForCompletion (in category 'as yet unclassified') -----
  waitForCompletion
  semaphore wait!

Item was changed:
+ ----- Method: AsyncFile>>writeBuffer:atFilePosition:onCompletionDo: (in category 'private') -----
- ----- Method: AsyncFile>>writeBuffer:atFilePosition:onCompletionDo: (in category 'as yet unclassified') -----
  writeBuffer: buffer atFilePosition: fPosition onCompletionDo: aBlock
  "Start an operation to write the contents of the buffer at given position in this file, and fork a process to await its completion. When the write completes, evaluate the given block. Note that, since the completion block runs asynchronously, the client may need to use a SharedQueue or a semaphore for synchronization."
 
  self primWriteStart: fileHandle
  fPosition: fPosition
  fromBuffer: buffer
  at: 1
  count: buffer size.
  "here's the process that awaits the results:"
  [| n |
  [ semaphore wait.
    n := self primWriteResult: fileHandle.
    n = Busy.
  ] whileTrue.  "loop while busy in case the semaphore had excess signals"
  n = ErrorCode ifTrue: [^ self error: 'asynchronous write operation failed'].
  n = buffer size ifFalse: [^ self error: 'did not write the entire buffer'].
  aBlock value.
  ] forkAt: Processor userInterruptPriority.
  !

Item was removed:
- ----- Method: DirectoryEntry class>>name:creationTime:modificationTime:isDirectory:fileSize: (in category 'deprecated') -----
- name: name0  creationTime: creationTime  modificationTime: modificationTime   isDirectory: isDirectory  fileSize: fileSize
- "This is the legacy creation method we are trying to phase out.  Please use #directory:  name:  creationTime:  modificationTime:  fileSize:."
- | type |
- type := isDirectory
- ifTrue: [ DirectoryEntryDirectory ]
- ifFalse: [ DirectoryEntryFile ].
- ^ type
- directory: nil
- name: name0  
- creationTime: creationTime  
- modificationTime: modificationTime  
- fileSize: fileSize!

Item was changed:
+ ----- Method: FilePath class>>classVersion (in category 'accessing') -----
- ----- Method: FilePath class>>classVersion (in category 'as yet unclassified') -----
  classVersion
 
  ^ 1.
  !

Item was changed:
+ ----- Method: RemoteString class>>currentTextAttVersion (in category 'accessing') -----
- ----- Method: RemoteString class>>currentTextAttVersion (in category 'as yet unclassified') -----
  currentTextAttVersion
  "The current configuration of the TextAttributes classes has a structures array describing the inst vars of the classes (SmartRefStream instVarInfo:).  Return tag that indexes the TextAttributeStructureVersions dictionary (4 random characters)."
 
  ^ CurrentTextAttVersion
  "Be sure to run makeNewTextAttVersion when any TextAttributes class changes inst vars"!

Item was changed:
+ ----- Method: RemoteString class>>initialize (in category 'class initialization') -----
- ----- Method: RemoteString class>>initialize (in category 'as yet unclassified') -----
  initialize
  "Derive the current TextAttributes classes object structure"
 
  self new makeNewTextAttVersion!

Item was changed:
+ ----- Method: RemoteString class>>newFileNumber:position: (in category 'instance creation') -----
- ----- Method: RemoteString class>>newFileNumber:position: (in category 'as yet unclassified') -----
  newFileNumber: sourceIndex position: anInteger
+ "Answer an instance of me for a file indexed by sourceIndex, at the
- "Answer an instance of me fora file indexed by sourceIndex, at the
  position anInteger. Assume that the string is already stored on the file
  and the instance will be used to access it."
 
  ^self new fileNumber: sourceIndex position: anInteger!

Item was changed:
+ ----- Method: RemoteString class>>newString:onFileNumber: (in category 'instance creation') -----
- ----- Method: RemoteString class>>newString:onFileNumber: (in category 'as yet unclassified') -----
  newString: aString onFileNumber: sourceIndex
  "Answer an instance of me for string, aString, on file indexed by
  sourceIndex. Put the string on the file and create the remote reference."
 
  ^self new string: aString onFileNumber: sourceIndex!

Item was changed:
+ ----- Method: RemoteString class>>newString:onFileNumber:toFile: (in category 'instance creation') -----
- ----- Method: RemoteString class>>newString:onFileNumber:toFile: (in category 'as yet unclassified') -----
  newString: aString onFileNumber: sourceIndex toFile: aFileStream
  "Answer an instance of me for string, aString, on file indexed by
  sourceIndex. Put the string on the file, aFileStream, and create the
  remote reference. Assume that the index corresponds properly to
  aFileStream."
 
  ^self new string: aString onFileNumber: sourceIndex toFile: aFileStream!

Item was changed:
+ ----- Method: RemoteString class>>structureAt: (in category 'accessing') -----
- ----- Method: RemoteString class>>structureAt: (in category 'as yet unclassified') -----
  structureAt: styleVersion
 
  ^ TextAttributeStructureVersions at: styleVersion ifAbsent: [nil]!