Path: csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: A "current directory" concept for Java... Date: Fri, 22 Aug 2014 19:45:07 -0400 Organization: A noiseless patient Spider Lines: 45 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 22 Aug 2014 23:45:32 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="b896cb427f8c4d19d14880347aa9d6ce"; logging-data="28810"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+y4u7+O+grg4OKwkkOJnwWpT0dZJPMc1g=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.7.0 In-Reply-To: Cancel-Lock: sha1:FV09lhWtheel8DUBIqAgBtMb0bA= Xref: csiph.com comp.lang.java.programmer:29813 On 08/22/2014 12:49 PM, Andreas Leitgeb wrote: > I'm fully aware, that the concept of a mutable "current directory" > for the whole VM does not work at all well with threads, and thus > there is of course no such thing like "System.chDir(...)" in Java. > > Instead, I'd like to use a mutable Wrapper for java.nio.file.Path > and whereever I need to access a file, I'd call a method on the > wrapper and that would check, if the file's path is a relative > or an absolute one, and eventually join it with the wrapped Path > object. The wrapper itself then could offer something like a chDir() > method to replace its wrapped Path by a target Path after following > a series of ".."(for stepping up to the Parent-dir), or subfolders. > > e.g.: the wrapped Path of curDir originally points to "/tmp", then... > - curDir.chDir("foo") would go to "/tmp/foo", then > - curDir.chDir("../bar") would go to "/tmp/bar", then > - curDir.chDir("/foo") would go to "/foo" > Whether it would check the file system about each of these > paths, and whether it would resolve symlinks or just use them > verbatim, is not among the things I care for at this point. > > With that, the concept of "current directory" would be tied to > a particular "curDir" object, and the user would be responsible > to either keep it to a single thread, or at least care about > proper synchronisation across threads (as with all mutable objects). > > I had a look at the classes/interfaces in java.(n)io, but couldn't > find such a class. Is it not there, or did I just miss it? It seems to me that a "process" might have a notion of a "current directory". And that a file system "traverser" might have its notion of a "current directory". But any set of classes implementing a "virtual file system" wouldn't need the concept of a "current directory". May be that there is better place to "home" the abstraction. > While it wouldn't be too hard to implement it for a particular > platform, getting it right for different platforms (maybe even > platforms where absolute/relative paths follow different patterns) > would be tricky enough, that I'd rather use a library classes (if > one exists), than roll my own. > > PS: Java 7 here >