Hi all,

As I have already been posting about my GSoC work and updates on my  blog
<https://vineetreddy.wordpress.com>   and on the mailing  list
<http://forum.world.st/template/NamlServlet.jtp?macro=search_page&node=1294792&query=gsoc+Rajula+&days=0>
 
. In this post, I would like to go in depth of my work on 'the working
directory'  so that I can get valuable feedback and suggestions from
everyone. This discussion was started on an  github PR
<https://github.com/pharo-project/pharo/pull/96>   which was conflicting my
PR.

Firstly, I would like to go through the current implementation of the
working directory. With this implementation, when you use the
defaultWorkingDirectory method, the directory in which the running image is
present in, is returned. This is not a completely good working because when
you run the image from a different directory like './pharo ../Pharo.image'
the working directory is the one in which your image resides. But that isn`t
your actual working directory. Due to this,

1. Pharo cannot be installed as a normal application in a read-only
environment.
2. Pharo wrongly reads and writes files relative to the 'working directory'.
3. It also makes scripting difficult.

In the FogBugz issue  here
<https://pharo.fogbugz.com/f/cases/5723/Default-Working-Directory>  , there
is an example which explains the problem.

Let say the Pharo VM and Image are in the directory "~/Pharo",
and I wrote a script in "~/Documents/Pharo-scripts" called
"perfect-numbers.st"

I have 2 possibilities:

cd ~/Pharo && pharo Pharo.image st
~/Documents/Pharo-scripts/perfect-numbers.st // works

or

cd ~/Documents/Pharo-scripts && pharo ~/Pharo/Pharo.image st
perfect-numbers.st // doesn't work...

It doesn't work because when pharo wants to load the file,
it tries to locate it with: FileSystem disk workingDirectory !!!
which is NOT the current working directory."

I hope you get the problem. 

So for the  new implementation <https://github.com/rajula96reddy/pharo-cli>  
with the help of Guille I researched about $PWD and getcwd() for a while and
wrote a new implementation. This is how it goes
1. I have written new methods in OSPlatorm 'getPwdFromFFI' and
'getPwdFromFFIwithsize:'. These call the getcwd() function using the  UFFI
2. And a new method currentWorkingDirectoryPath and
currentWorkingDirectoryPathWithBufferSize: in OSPlatform which uses the
above method and gets the working directory.
3. To integrate this, I have patched the DiskStore method
'defaultWorkingDirectory' to use the new methods in OSPlatform.

I have checked all the sendors of the 'defaultWorkingDirectory' for any
issue. And I also wrote some unit tests. So, the new implementation is
working fine. With this, now I am able to get the right working directory.
The example mentioned above works perfectly. 

But, there may be a few cases where it can break interoperability between
Pharo and other Smalltalk dialects like squeak etc.  And the 'pharo-local'
directory and its methods should also be patched subsequently. In fact,
these problems can be tackled by running image from its own directory itself
(which is obvious ;) ) or by using the method imageDirectory in FileLocator
class explicitly when necessary. But overall a good thing is this is will
ensure the system will behave as in other languages.

I have completed this implementation and submitted a  PR
<https://github.com/pharo-project/pharo/pull/92>   to github. But because of
some dependency issue, it has not yet been merged. With the help of my
mentor, I am working on the problem.

Thanks for reading all this. Please give your feedback and comments on this
new implementation. Your suggestions help me in learning more about the
project and also about the organization.

Thanks,
Rajula



--
View this message in context: 
http://forum.world.st/The-new-implementation-of-current-working-directory-tp4952918.html
Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.

Reply via email to