I'm making a little app that requires this folder .timeclock/filename
The first time the app runs I would like it to check to see if the
folder and file are there and if not, create them. Everything I've tried
crashes if the folder isn't there. Thanks for any help!
From there you should be able to just open .timeclock/new_file as one normally would.
matthew smillie.
···
On Jan 30, 2006, at 16:39, charlie bowman wrote:
I'm making a little app that requires this folder .timeclock/filename
The first time the app runs I would like it to check to see if the
folder and file are there and if not, create them. Everything I've tried
crashes if the folder isn't there. Thanks for any help!
irb(main):002:0> Dir.mkdir(".timeclock")
won't the above faile once the directory is created. I need to run a
check each time the application is ran.
Matthew Smillie wrote:
···
On Jan 30, 2006, at 16:39, charlie bowman wrote:
I'm making a little app that requires this folder .timeclock/filename
The first time the app runs I would like it to check to see if the
folder and file are there and if not, create them. Everything I've
tried
crashes if the folder isn't there. Thanks for any help!
These methods might help you out with creating the directory:
Yes, that's why you wrap it in an if (or unless) statement.
unless File.exist?(".timeclock")
Dir.mkdir(".timeclock")
end
# Optionally make sure .timeclock is a directory
unless File.directory?(".timeclock")
puts ".timeclock is a not a directory."
exit( 1 )
end
# do whatever.
···
On Jan 30, 2006, at 12:09 PM, charlie bowman wrote:
irb(main):002:0> Dir.mkdir(".timeclock")
won't the above faile once the directory is created. I need to run a
check each time the application is ran.
may be it would fail. but you have the other method(s) that you can use to
check if the directory exists.
konstantin
"charlie bowman" <cbowmanschool@yahoo.com> wrote in message
news:5d2bdb4af4e0aab57e66d7fe58f508ac@ruby-forum.com...
···
irb(main):002:0> Dir.mkdir(".timeclock")
won't the above faile once the directory is created. I need to run a
check each time the application is ran.
Matthew Smillie wrote:
On Jan 30, 2006, at 16:39, charlie bowman wrote:
I'm making a little app that requires this folder .timeclock/filename
The first time the app runs I would like it to check to see if the
folder and file are there and if not, create them. Everything I've
tried
crashes if the folder isn't there. Thanks for any help!
These methods might help you out with creating the directory:
On Jan 30, 2006, at 12:09 PM, charlie bowman wrote:
irb(main):002:0> Dir.mkdir(".timeclock")
won't the above faile once the directory is created. I need to run a
check each time the application is ran.
Yes, that's why you wrap it in an if (or unless) statement.
unless File.exist?(".timeclock")
Dir.mkdir(".timeclock")
end
# Optionally make sure .timeclock is a directory
unless File.directory?(".timeclock")
puts ".timeclock is a not a directory."
exit( 1 )
end
# do whatever.
one cannot both check and/or create a dir in an atomic fashion. in fact, one
cannot even create a dir in an atomic fashion on some filesystems. about the
best you can do is
class Dir
def self::create d
begin
mkdir d # always try to create it
rescue Errno::EEXIST
nil # ignore failure to do so
end
new d # this will throw an error if it does not exist!
end
end
regards.
-a
···
On Tue, 31 Jan 2006, Logan Capaldo wrote:
On Jan 30, 2006, at 12:09 PM, charlie bowman wrote:
irb(main):002:0> Dir.mkdir(".timeclock")
won't the above faile once the directory is created. I need to run a
check each time the application is ran.
Yes, that's why you wrap it in an if (or unless) statement.
unless File.exist?(".timeclock")
Dir.mkdir(".timeclock")
end
# Optionally make sure .timeclock is a directory
unless File.directory?(".timeclock")
puts ".timeclock is a not a directory."
exit( 1 )
end
# do whatever.
--
sleep is the best meditation. -- h.h. the 14th dali lama
"Logan Capaldo" <logancapaldo@gmail.com> wrote in message
news:DFC45DE6-0CCF-40CE-A21B-8BCCE7674C71@gmail.com...
···
On Jan 30, 2006, at 12:09 PM, charlie bowman wrote:
irb(main):002:0> Dir.mkdir(".timeclock")
won't the above faile once the directory is created. I need to run a
check each time the application is ran.
Yes, that's why you wrap it in an if (or unless) statement.
unless File.exist?(".timeclock")
Dir.mkdir(".timeclock")
end
# Optionally make sure .timeclock is a directory
unless File.directory?(".timeclock")
puts ".timeclock is a not a directory."
exit( 1 )
end
# do whatever.
While this is true, I think it only matters when one is dealing with
multi-process and/or multi-threaded code, which I doubt the original
poster is. But I know that multi-processing is about all you do Ara,
so I guess it is hard to forget lessons like this!
Ryan
···
On 1/30/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
one cannot both check and/or create a dir in an atomic fashion. in fact, one
cannot even create a dir in an atomic fashion on some filesystems. about the
best you can do is
On Wednesday 01 February 2006 22:42, konsu wrote:
####################################################################
class Dir
def ensure_dir(name)
Dir.mkdir name
rescue Errno::EEXIST
raise Errno::ENOTDIR, name, caller unless File.directory?(name)
end
end
heh - i probably do get a little pedantic with that stuff - but it's so hard
to debug i just try to avoid it all together!
-a
···
On Tue, 31 Jan 2006, Ryan Leavengood wrote:
On 1/30/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
one cannot both check and/or create a dir in an atomic fashion. in fact, one
cannot even create a dir in an atomic fashion on some filesystems. about the
best you can do is
While this is true, I think it only matters when one is dealing with
multi-process and/or multi-threaded code, which I doubt the original poster
is. But I know that multi-processing is about all you do Ara, so I guess it
is hard to forget lessons like this!
--
sleep is the best meditation. -- h.h. the 14th dali lama
On 1/30/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
one cannot both check and/or create a dir in an atomic fashion. in fact, one
cannot even create a dir in an atomic fashion on some filesystems. about the
best you can do is
While this is true, I think it only matters when one is dealing with
multi-process and/or multi-threaded code, which I doubt the original
poster is. But I know that multi-processing is about all you do Ara,
so I guess it is hard to forget lessons like this!
Ryan
Not necessarily - the program could check for the existence of the directory, then something else (another program, the user, etc.) could create or remove the directory. Not very likely, but it could happen. Probably not worth worrying about though, huh?
Thanks for the tip! This is just a personal timekeeper for me. But I
will keep that in mind if I need to do any threaded apps.
unknown wrote:
···
On Tue, 31 Jan 2006, Ryan Leavengood wrote:
On 1/30/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
one cannot both check and/or create a dir in an atomic fashion. in fact, one
cannot even create a dir in an atomic fashion on some filesystems. about the
best you can do is
While this is true, I think it only matters when one is dealing with
multi-process and/or multi-threaded code, which I doubt the original poster
is. But I know that multi-processing is about all you do Ara, so I guess it
is hard to forget lessons like this!
heh - i probably do get a little pedantic with that stuff - but it's so
hard
to debug i just try to avoid it all together!
Not necessarily - the program could check for the existence of
the directory, then something else (another program, the user,
etc.) could create or remove the directory. Not very likely, but
it could happen. Probably not worth worrying about though, huh?
It's probably worth working out what a sane way to fail in that case
would be; stuff like that can have security implications.
<ara.t.howard@noaa.gov> wrote in message
news:Pine.LNX.4.62.0601301323530.4780@harp.ngdc.noaa.gov...
heh - i probably do get a little pedantic with that stuff - but it's so
hard
to debug i just try to avoid it all together!
i think it is not possuble to avoid this problem in a web application which
caches its output in the server's filesystem. is it?
your code returns an error if it cannot create the file, how do you handle
this error? when trying to create a cache in a web application, would sleep
and retry strategy be reasonable here?
If it has to be a file, I would use unique names keyed to the session id or user name or whatever you happen to be tracking.
Imagine trying to sleep & retry for even 10 concurrent requests. Ick.
matthew smillie.
···
On Feb 1, 2006, at 21:43, konsu wrote:
hello,
<ara.t.howard@noaa.gov> wrote in message
news:Pine.LNX.4.62.0601301323530.4780@harp.ngdc.noaa.gov...
heh - i probably do get a little pedantic with that stuff - but it's so
hard
to debug i just try to avoid it all together!
i think it is not possuble to avoid this problem in a web application which
caches its output in the server's filesystem. is it?
your code returns an error if it cannot create the file, how do you handle
this error? when trying to create a cache in a web application, would sleep
and retry strategy be reasonable here?