[ENH]VMMaker file copying plugin
Tim Rowledge
tim at sumeru.stanford.edu
Fri Apr 27 23:40:08 UTC 2001
Here is a trivial fix/workaround/what have you for the problem of
copying file/dirs without losing the type and other attributes.
A copy has also been added to my website, along with an Acorn
implementation of the platform support (one measly little function) for
example reference.
tim
--
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
Let the machine do the dirty work. - Elements of Programming Style
-------------- next part --------------
'From Squeak3.1alpha [latest update: #''Squeak3.1alpha'' of 7 March 2001 update 3888] on 27 April 2001 at 4:31:05 pm'!
"Change Set: VMMAaker3-1version-fileCopy
Date: 27 April 2001
Author: tim at sumeru.stanford/.edu
Add a trivial plugin to provide access to the platform file/directory copying function. This allows us to keep the assorted file permissions and type info intact when copying various VM files around.
A platform support file is required - basically all you need is to implement sqCopyFilesizetosizerecurse( char * srcName,
int srcSz, char * dstName, int dstSz, int recurse) such that the file/dir srcName is copied to dstName with recursion down the treee if recurse is true. On unix this would probably work with a simple 'system(cp -r srcName dstName' or similar.
You will need to have already filed in the main VMMaker3-1version changes."!
TestInterpreterPlugin subclass: #FileCopyPlugin
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'VMConstruction-Plugins'!
!FileCopyPlugin commentStamp: 'tpr 4/26/2001 18:13' prior: 0!
This plugin is a simple workaround for the lamentable state of the Squeak file handling system; it provides a primitive to copy a file or tree via the OS facility and thus preserve all the OS attributes in the most trivial possible manner. Not intended for a long life and should be replaced by better code as soon as possible!
!FileCopyPlugin methodsFor: 'system primitives' stamp: 'tpr 4/27/2001 12:24'!
primitiveFile: srcName copyTo: dstName recurse: recurse
|srcSz dstSz ok |
self primitive: 'primitiveFileCopy'
parameters: #(String String Boolean).
srcSz _ interpreterProxy slotSizeOf: srcName cPtrAsOop.
dstSz _ interpreterProxy slotSizeOf: dstName cPtrAsOop.
ok _ self sqCopyFile: srcName size: srcSz to: dstName size: dstSz recurse: recurse.
^ok asBooleanObj
! !
!FileCopyPlugin class methodsFor: 'translation' stamp: 'tpr 4/27/2001 11:02'!
requiresPlatformFiles
"this plugin requires platform specific files in order to work"
^true! !
!VMMaker methodsFor: 'private- copying files' stamp: 'tpr 4/27/2001 12:16'!
copyFilesFromSourceDirectory: srcDir toTargetDirectory: dstDir recursively: recurseBoolean
"copy all files and subdirectories from srcDir to dstDir, optionally recursing down the tree.
It is assumed that both directories already exist and have appropriate
permissions - proper error handling ought to be provided sometime.
Note how nice it would be if the file system classes already did this;
why, they could even defer to an improved file plugin for some of
these things."
"copy all the files"
| fileList dirList src dst done |
done _ self primitiveCopyFilesFromSourceDirectoryNamed: srcDir pathName toTargetDirectoryNamed: dstDir pathName recursively: recurseBoolean.
done ifTrue:[^self].
fileList _ srcDir fileNames.
fileList do: [:filenm |
[src _ srcDir fileNamed: filenm.
src ifNil: [^ self couldNotOpenFile: (srcDir fullNameFor: filenm)].
dst _ dstDir newFileNamed: filenm.
dst ifNil: [^ self couldNotOpenFile: (dstDir fullNameFor: filenm)].
Transcript show: 'copy ', (srcDir fullNameFor: filenm); cr.
self copyFromFileStream: src to: dst]
ensure:
[src ifNotNil: [src close].
dst ifNotNil: [dst close]]].
recurseBoolean ifFalse:[^self].
"If we are recursing create the subdirectories of srcDir in dstDir, and then copy that
subtree "
dirList _ srcDir directoryNames.
dirList do:
[:newDstDir |
(dstDir directoryExists: newDstDir)
ifFalse: [dstDir createDirectory: newDstDir].
self copyFilesFromSourceDirectory: (srcDir directoryNamed: newDstDir)
toTargetDirectory: (dstDir directoryNamed: newDstDir)]! !
!VMMaker methodsFor: 'private- copying files' stamp: 'tpr 4/27/2001 12:21'!
primitiveCopyFilesFromSourceDirectoryNamed: srcDir toTargetDirectoryNamed: dstDir recursively: recurseBoolean
"copy all files and subdirectories from srcDir to dstDir, optionally recursing down the tree. Defer to the OS is there is a suitable plugin available"
<primitive: 'primitiveFileCopy' module: 'FileCopyPlugin'>
^false! !
!VMMaker class methodsFor: 'accessing' stamp: 'tpr 4/27/2001 16:15'!
providedPlugins
"We really ought to come up with a clean way to enumerate all the plugins rather than having a literal list. Unfortunately not all the subclasses of InterpreterPlugin are legitimate translatable plugins.
This list is manually derived from 'InterpreterPlugin allSubclasses', with the various test classes, several 3D, MPeg etc classes left out since they don't get included in current distributions.
Note also that for bizarre historical reasons not all plugin classes produce a plugin of the same name. For example, DeflatePlugin produces 'ZipPlugin', BalloonEnginePlugin produces 'B2DPlugin' etc. Really irritating"
^#(ADPCMCodecPlugin
AsynchFilePlugin
B3DEnginePlugin
BalloonEnginePlugin
BitBltSimulation
DSAPlugin
DeflatePlugin
DropPlugin
FFIPlugin
FFTPlugin
FilePlugin
FileCopyPlugin
FloatArrayPlugin
JPEGReaderPlugin
JoystickTabletPlugin
KlattSynthesizerPlugin
LargeIntegersPlugin
MIDIPlugin
Matrix2x3Plugin
MiscPrimitivePlugin
SecurityPlugin
SerialPlugin
SocketPlugin
SoundCodecPlugin
SoundGenerationPlugin
SoundPlugin
StarSqueakPlugin
SurfacePlugin)! !
More information about the Squeak-dev
mailing list
|