From: David Bolen Date: 2001-11-21T10:12:53+09:00 Subject: [ruby-talk:25971] Re: Ruby in windows "Mark Hahn" writes: > Thanks for the detailed explanation. Modifying the cygwin mount isn't > feasible since anyone using my code would have to have the same mount. For > that matter, how do I know what mount the user has used? > > I thought I understood you, but now I just did another test and I am really > confused. I ran Dir.pwd from "c:\cygwin\" and got "/" as the result. Why > didn't it say "/cygdrive/c/cygwin/"? I'm guessing that your Cygwin installation was installed into c:\cygwin and that the directory was mounted as your root filesystem (e.g., "/"). I only work with my own Cygwin installation and not Ruby-only, so I'm not sure if this is the default if you're only using Ruby but otherwise don't have Cygwin on your system. Thus, when asked to produce a path, Cygwin will always try to produce a path that makes sense within its POSIX emulation. So in this case, c:\cygwin is really /, and that's what it displays. The "/cygdrive" prefix is only something the Cygwin DLL uses when it has no proper mapping for a directory into its POSIX-emulation namespace. However, it's always safe for you to use it in application code to refer to a specific path. The DLL (at least recent versions) also interprets paths just using backslashes as being a native Windows path, so I would think that using a Windows notation would work, unless path components got in the way of utilities in use (e.g., some Unix based utilities may use a colon as a separator). > This certainly doesn't satisfy my personal POLS. Not sure what POLS is, but the approach taken by Cygwin is actually pretty flexible and reasonable to me, if you realize that the entire point of Cygwin is POSIX emulation under Windows. It's not just trying to let a Unix program run under Windows, but actually provide an environment familiar to that program and one that doesn't violate any rules expected by that program. Thus, there's no such thing as drive letters, but you have to have some way to map a POSIX like filesystem to a Windows like filesystem, including across drives. A normal Cygwin installation will have a full installation tree (/, /usr, /bin, /etc, etc...) beneath some location on the system where it is installed. As far as any Cygwin utility is concerned that location is "/" (regardless of underlying Windows path). Any directory outside of that tree can be "mounted" inside the tree if desired, the "cygdrive" pseuso-root directory is provided for manual access outside the tree but using POSIX paths, and a native windows path (backslashes) can be used when not precluded by the applications in use. Whenever returning current directory information, Cygwin will obey its mount table for creating paths, or use /cygdrive for areas outside its control to still stay POSIX path compatible. A utility that comes with a Cygwin installation, cygpath, let's you perform various conversions from Cygwin paths to Windows paths and vice versa. There are also some internal API entry points exported from the DLL that can be used for that purpose, but the normal POSIX emulation (such as getcwd) are always going to prefer Cygwin based paths, since that's the point of the emulation. This is probably less confusing for someone already using Cygwin and just treating Ruby as yet another Unix application running within the Cygwin environment, then it would be if Ruby were the only Cygwin related application running on a system. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l@fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/