Return value of make-dir

Started by Excalibor, March 05, 2009, 03:32:43 AM

Previous topic - Next topic

Excalibor

Greetings,



Recently I found out that a script of mine stopped working under cygwin when it had been working OK for weeks.



Debugging it, I found out that, for some reason, the permissions on the base directory were incorrect and the user the script was running under couldn't create a new directory. Now, the script makes a new directory every day (based on the current date) and that's obviously bad.



Unless I'm wrong (which is, after all, very probable) make-dir just returns true or false accordingly to it being able to create or not the new directory.



Is there a system variable where I can check the reason why it hasn't been able to create the new directory? If not, would it be possible to provide it in further releases? Because it was as simple as issuing a chmod command (with the same user, it was the owner, but mod had been changed to 0444 for some reason) and that can be coded into the script.



thanks!

Lutz

#1
Most functions in newLISP dealing with files and directories return 'nil' when the underlying operating system functions fails.



You can use the newLISP function 'sys-error' to find out what went wrong. The following interactive session illustrates this:


> (open "abcxyz" "read")
nil
> (sys-error)
2
> (sys-error 2)
"No such file or directory"
>






Ps: note that in the upcoming maintenance 10.0.2 update the error text is included in the return value from 'sys-error' as a list of error-number and error text. Instead of returning: 2 it will return (2  "No such file or directory").

Excalibor

#2
Quote from: "Lutz"Most functions in newLISP dealing with files and directories return 'nil' when the underlying operating system functions fails.



You can use the newLISP function 'sys-error' to find out what went wrong. The following interactive session illustrates this:


Ah, cool... This means I can wrap the system call and the system error call in the same macro so I don't lose its content... in the spirit of Scheme:


(with-make-dir directory mode
  (if  (= (sys-error) 1)... ))
# Either success or cond on the posible values to rescue from...
#  maybe a try/catch will be more useful...


I'll give it a try tomorrow... :-)



Thanks!