FileDirectory and ReferenceStream Class equivalents in Pharo?

北慕城南 提交于 2019-12-08 01:10:33

问题


I'm doing the persistance example at:

http://book.seaside.st/book/advanced/persistency/image-based-persistency

It involves creating a method that uses the FileDirectory class like this:

SMFileDatabase class>>backupDirectory
    ^ (FileDirectory default directoryNamed: self name) assureExistence.

Pharo seems to be unable to find the Class and the closest that comes out in search is FileDirectoryWrapper. Will this do?

NB. I can't figure this out myself since I've never used FileDirectory or FileDirectoryWrapper before so I'm in the dark.

Later edit:

Found another one ReferenceStream. They both seem to have been deprecated. Mentioned here: http://lists.gforge.inria.fr/pipermail/pharo-project/2012-June/065765.html

Because they apparently had problems, mentioned here: Smalltalk ReferenceStream has problems with new instance variables?

Later edit 2:

It seems the answers below will work for FileDirectory, and ReferenceStream can be replaced by Fuel in newer Pharo releases. https://stackoverflow.com/a/15742159/293856

SmartRefStrem seems another solution to the bugs. All this is untested by me. Smalltalk ReferenceStream has problems with new instance variables?

However:

Those wanting to finish the example in the book need to go back in time and get a Pharo 1.4 from: https://gforge.inria.fr/frs/?group_id=1299

Scroll down and look for One-Click Pharo 1.4 and get the latest build, if there is a newer one than: https://gforge.inria.fr/frs/download.php/file/31359/Pharo-1.4-14457-OneClick.zip

or 1.3.

I got lucky with a Pharo VM from here: http://files.pharo.org/vm/pharo/20/mac/stable.zip

With a prebuilt Seaside image running on Pharo 1.3 here: http://www.seaside.st/distributions/Seaside-3.0.7-final.zip

Get your code out of the current image via Monticello and then "back" into the older image. Success!


回答1:


The simplest way to do it is like this:

self name asFileReference ensureCreateDirectory.



回答2:


Pharo switched to FileSystem some time after the book was published.

The equivalent for the first code is now

SMFileDatabase class>>backupDirectory
    ^(FileSystem disk workingDirectory / self name) ensureCreateDirectory

(also, regarding ReferenceStream, the answer given by Damien in the post you referenced still holds true)



来源:https://stackoverflow.com/questions/28285936/filedirectory-and-referencestream-class-equivalents-in-pharo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!