How can I marshall File::Stat, and do file tests?

S

Sam Roberts

Basically, I'm building a Hash of paths to their File::Stat, and
Marshal.dumping it. Later I'll load it, and
compare the current filesystem state to the state I saved.

Simple, right?

But, I can't marshall File::Stat, it's not allowed/supported.

Irritating, but no problem, I'll build a Struct with all the values from
the File::Stat that I want to save, and put that in the Hash instead,
right?

Well, that doesn't work so well, either. Now when I load that, I have
no way to construct a File::Stat out of my own data (it lacks a "new"),
and I lose all of File::Stats handy methods to see what kind of file it
is, and its permissions, etc.

Any suggestions? Can I define my own _load() and _dump() for File::Stat?
Is that the right way? Am I not allowed to marshall File::Stat because
its contents are system specific?

Thanks for any pointers on how to deal with this,
Sam
 
S

Sam Roberts

Seems to be a long-standing oddity, discussed in ruby-talk #74175 and
#74162, but I still can't find a resolution to it.

Still searching...

Sam

Quoteing (e-mail address removed), on Sun, Nov 02, 2003 at 12:08:34PM +0900:
 
S

Sam Roberts

Does nobody really care that this doesn't work? Is it that its fixed in
1.8, or something?

~/ruby $ ruby -e 's=File.stat("/");Marshal.dump(s);'
-e:1:in `dump': can't dump File::Stat (TypeError)
from -e:1
~/ruby $ ruby -v
ruby 1.6.7 (2002-03-01) [powerpc-darwin6.0]

Sam

Quoteing (e-mail address removed), on Mon, Nov 03, 2003 at 05:20:01AM +0900:
 
Y

Yukihiro Matsumoto

Hi,

In message "bug? ruby -e 's=File.stat("/");Marshal.dump(s);'"

|Does nobody really care that this doesn't work? Is it that its fixed in
|1.8, or something?

Not "fixed" in 1.8 either.

matz.
 
S

Sam Roberts

Is it a "feature", then?

If so, may I ask why?

I don't understand why a files stat would be unmarshable, even in
C I could write a stat_t to file.

Thanks,
Sam

Quoteing (e-mail address removed), on Thu, Dec 04, 2003 at 11:27:30AM +0900:
 
Y

Yukihiro Matsumoto

In message "Re: bug? ruby -e 's=File.stat("/");Marshal.dump(s);'"
|
|Is it a "feature", then?
|
|If so, may I ask why?

It's just because I haven't decided how to dump File::Stat object.

|I don't understand why a files stat would be unmarshable, even in
|C I could write a stat_t to file.

But you don't do it in C for portability, do you?

matz.
 
S

Sam Roberts

Quoteing (e-mail address removed), on Thu, Dec 04, 2003 at 02:56:07PM +0900:
In message "Re: bug? ruby -e 's=File.stat("/");Marshal.dump(s);'"
|Is it a "feature", then?
|If so, may I ask why?

It's just because I haven't decided how to dump File::Stat object.

OK, I begin to understand.

You can't just write all the fields when marshalling?

#<File::Stat dev=234881029, ino=1357757, mode=17407, nlink=10, uid=0,
gid=0, rdev=0, size=340, blksize=4096, blocks=0, atime=Sat Dec 06
08:56:41 EST 2003, mtime=Sat Dec 06 11:57:09 EST 2003, ctime=Sat Dec
06 11:57:09 EST 2003>

Maybe the answer is that File::Stat looks different on other systems?

Even if I save all these fields, File::Stat doesn't have a constructor I
can use, so I have no way to make a File::Stat out of information I
save!

Can I create, somehow, an initializer like:

File::Stat.new2(dev,ino,mode,nlink,uid,gid,rdev,size,.... etc...)?

I want a File::Stat, because it has many useful methods, and I have
had to write them myself since I wrote my own equivalent class that
can be written to disk.

Or, if I don't need portable, could I extend File::Stat to support being
marshalled? Would that be a 'back door' way that would allow me to
create one?
|I don't understand why a files stat would be unmarshable, even in
|C I could write a stat_t to file.

But you don't do it in C for portability, do you?

Yes, but I don't need portability. I am doing it in Ruby because of
speed of prototyping, the plan was to rewrite it in C later, using dbm
to store struct_t's, if ruby is too slow. So far, ruby is fast enough,
but development was less trivial than expected because of this
difficulty.

Thanks,
Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,361
Latest member
eitamoro

Latest Threads

Top