Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!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 14:50:57 -0400 Organization: A noiseless patient Spider Lines: 41 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 18:51:22 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="b896cb427f8c4d19d14880347aa9d6ce"; logging-data="7745"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+iCw67p/ePlpY0/gEZhxFws5un6uN3Xhw=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.7.0 In-Reply-To: Cancel-Lock: sha1:Cox4HwNh14wQim5G7Sy3aPugt9k= Xref: csiph.com comp.lang.java.programmer:29805 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? > > 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. Yep, very likely given: > > PS: Java 7 here >