Submitted by : Simon Michael at: 2004-09-29T12:22:41+00:00 (13 years ago)
Name :
Category : Severity : Status :
Optional subject :  
Optional comment :


comments:

(new) chdir in pagetypes and plugins alters current directory --Simon Michael, Wed, 29 Sep 2004 12:22:43 -0700 reply
Kai Hoppert wrote:

Hi,

in __init__.py line 113 you make a chdir

it would be nice if there can be a change back to the original path before because this can make problems with other products . If you start a zope instance and change directory. the position is hold there and other product (for example textindexng with wich i have this problem) only want to create a file. and if you changed it he want to create or access the file (textindexng.log) in the wrong directory.

Hello Kai.. that is a valuable clue that explains some things, thank you. I'm forwarding to the tracker to open an issue. If anyone has a fix, please post.

(new) chdir in pagetypes and plugins alters current directory --Bob McElrath?, Wed, 29 Sep 2004 13:13:22 -0700 reply
I learned the hard way not to use chdir in zope code.

You can't be sure what the current directory is and you can't be sure where to chdir back to. Changing the working dir while zope is running can have very unexpected consequences for other parts of zope which may run.

Always use absolute paths.

For latexwiki when latex/dvips needs to create temporary files, I cd in a subshell, so the zope working directory doesn't change.

Patch in my repo:

    http://bob.mcelrath.org/darcs/zwiki/

property change --simon, Wed, 29 Sep 2004 18:56:00 -0700 reply
Category: => general Severity: => normal Status: => open

thanks bob, pulled --simon, Wed, 29 Sep 2004 19:05:33 -0700 reply
Status: open => closed

aw: chdir in pagetypes and plugins alters current directory -- Thu, 30 Sep 2004 21:58:12 -0700 reply
Hi

originalPath=os.getcwd() os.chdir(originalPath)

will prevent in having this problem.

Path Changes are in

#pagetypes __init__.py

import os,glob originalPath=os.getcwd() os.chdir(__path__[0]?) modules = glob.glob(*.py) modules.remove(__init__.py) # force the usual ordering of standard page types in the editform firstmods = [stx.py,rst.py,wwml.py,html.py,'plaintext.py']? firstmods.reverse() for mod in firstmods: try: modules.remove(mod) modules.insert(0,mod) except ValueError?: pass for file in modules: __import__(Products.ZWiki.pagetypes.%s % file[:-3]?) os.chdir(originalPath)

#and plugins __init__.py

import os,glob originalPath=os.getcwd() os.chdir(__path__[0]?) modules = glob.glob(*.py) modules.remove(__init__.py) for file in modules: __import__(Products.ZWiki.plugins.%s % file[:-3]?) os.chdir(originalPath)

Greetings

Kai