caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Unix.stat sometimes fails on Win32 port
@ 2003-08-06 10:02 Richard Jones
  2003-08-06 14:39 ` David Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Jones @ 2003-08-06 10:02 UTC (permalink / raw)
  To: caml-list

Demonstration program below. Basically if you compile this and run

	winfiletest d c:\
	winfiletest d c:\temp
	winfiletest d c:\temp\      <-- this one fails
	winfiletest d c:\temp\.

This is specifically a problem with lablgtk2 which returns directory
names with a trailing slash from the file selection dialog. Works OK
on the Unix port, but fails under Windows.

Rich.

----------------------------------------------------------------------

open Unix

let perror f default =
  try f ()
  with
    Unix_error (errno, syscall, operand) ->
      Printf.eprintf "%s: %s: %s\n" syscall operand (error_message errno);
      Pervasives.flush Pervasives.stderr;
      default

(* Filename concatenation. *)
let (//) = Filename.concat

(* Check if path is a directory. *)
let is_dir path =
  perror (fun () -> (stat path).st_kind = S_DIR) false

(* Check if path is a file. *)
let is_file path =
  perror (fun () -> (stat path).st_kind = S_REG) false

let () =
  if Array.length Sys.argv < 3 then
    failwith "usage: winfiletest f|d name";
  if Sys.argv.(1) = "f" then
    if is_file Sys.argv.(2) then
      Printf.printf "is_file true\n"
    else
      Printf.printf "is_file false\n"
  else
    if is_dir Sys.argv.(2) then
      Printf.printf "is_dir true\n"
    else
      Printf.printf "is_dir false\n";

-- 
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you.
"My karma ran over your dogma"

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Unix.stat sometimes fails on Win32 port
  2003-08-06 10:02 [Caml-list] Unix.stat sometimes fails on Win32 port Richard Jones
@ 2003-08-06 14:39 ` David Brown
  2003-08-06 14:49   ` Richard Jones
  0 siblings, 1 reply; 5+ messages in thread
From: David Brown @ 2003-08-06 14:39 UTC (permalink / raw)
  To: Richard Jones; +Cc: caml-list

On Wed, Aug 06, 2003 at 11:02:25AM +0100, Richard Jones wrote:
> Demonstration program below. Basically if you compile this and run
> 
> 	winfiletest d c:\
> 	winfiletest d c:\temp
> 	winfiletest d c:\temp\      <-- this one fails
> 	winfiletest d c:\temp\.
> 
> This is specifically a problem with lablgtk2 which returns directory
> names with a trailing slash from the file selection dialog. Works OK
> on the Unix port, but fails under Windows.

Unix is being nice to you in stripping off the final slash.  Would it be
possible to wrap the stat call in something that checks for and removes
a trailing slash?

Dave Brown

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Unix.stat sometimes fails on Win32 port
  2003-08-06 14:39 ` David Brown
@ 2003-08-06 14:49   ` Richard Jones
  2003-08-06 16:21     ` David Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Jones @ 2003-08-06 14:49 UTC (permalink / raw)
  Cc: caml-list

On Wed, Aug 06, 2003 at 07:39:02AM -0700, David Brown wrote:
> Unix is being nice to you in stripping off the final slash.  Would it be
> possible to wrap the stat call in something that checks for and removes
> a trailing slash?

I worked around it by adding a "." to the end of the path in my
"is_dir" function if it's Windows and if it ends with a "\\" already,
but that still doesn't stop it from being a bug.

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you.
"My karma ran over your dogma"

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Unix.stat sometimes fails on Win32 port
  2003-08-06 14:49   ` Richard Jones
@ 2003-08-06 16:21     ` David Brown
  2003-08-06 17:01       ` John Carr
  0 siblings, 1 reply; 5+ messages in thread
From: David Brown @ 2003-08-06 16:21 UTC (permalink / raw)
  To: Richard Jones; +Cc: caml-list

On Wed, Aug 06, 2003 at 03:49:49PM +0100, Richard Jones wrote:
> On Wed, Aug 06, 2003 at 07:39:02AM -0700, David Brown wrote:
> > Unix is being nice to you in stripping off the final slash.  Would it be
> > possible to wrap the stat call in something that checks for and removes
> > a trailing slash?
> 
> I worked around it by adding a "." to the end of the path in my
> "is_dir" function if it's Windows and if it ends with a "\\" already,
> but that still doesn't stop it from being a bug.

But, it would be just as valid to argue that Unix has a bug in that it
doesn't detect an incorrectly formed pathname.

Dave Brown

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Unix.stat sometimes fails on Win32 port
  2003-08-06 16:21     ` David Brown
@ 2003-08-06 17:01       ` John Carr
  0 siblings, 0 replies; 5+ messages in thread
From: John Carr @ 2003-08-06 17:01 UTC (permalink / raw)
  To: caml-list


> But, it would be just as valid to argue that Unix has a bug in that it
> doesn't detect an incorrectly formed pathname.

It's not a bug, it's a feature.

POSIX requires that operations on "/directory/" and "/directory"
behave identically in most situations.  Since the module is named
"Unix" it ought to follow the Unix convention.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-08-06 17:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-06 10:02 [Caml-list] Unix.stat sometimes fails on Win32 port Richard Jones
2003-08-06 14:39 ` David Brown
2003-08-06 14:49   ` Richard Jones
2003-08-06 16:21     ` David Brown
2003-08-06 17:01       ` John Carr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).