The Current Directory

The notion of a "current directory" allows users (and applications) to use shorter relative pathnames for objects in the file system. This concept is common to all modern operating systems, and also to the classic Java runtime system.

However, there are important differences between the UNIX/Linux and classic Java models of the "current directory".

  1. The UNIX/Linux 'current directory' is part of the state of a process. Changing one processes current dierectory has no effect on the current directory of other processes. By contrast, the classic Java "current directory" is the value of a System property, and is shared by all entities in the VM.
  2. The UNIX/Linux 'current directory' is guaranteed to be a real directory at all times, even if that directory may be no longer accessible from a file system root. By contrast, the classic Java "current directory" may not exist, or may actually be a file.

The classic Java model of a "current directory" is problematic when we try to implement a command line interpretter. For example, consider the following "sh" command:

   tar cf - . | (cd /somewhere ; tar xf - )

It is difficult to support this in classic Java. It requires two instances of the "tar" command running in parallel with different current directories. I can think of just two ways to achieve this in classic Java:

  1. Run the two 'tar' command instances in different isolates each with their own 'current' directory. In general, is it hard to know when a command does not need to be run in an isolate.
  2. Use some JNode specific API that implements a UNIX-like model of the current directory to create File objects from pathnames. This means that typical Java apps need to be modified to work properly in JNode.

Neither of these approaches is satisfactory, IMO.

The alternative is to change the way that JNode implements the current directory. One possibility is to modify java.io.File to get the "current directory" from thread local state rather than from the System properties. This would allow us to implement per-command current directory with no change to classic Java apps. The only catch is that an app cannot "change directory" the old way; i.e. by updating the System property.

Any comments? Any alternatives?