|
In lugnet.cad.dev.org.ldraw, braml@juno.com (Bram Lambrecht) writes:
> I wrote:
> > Unzipping or splitting an MPD should create the directories correctly
> > if they don't already exist (I hope). We should check if splitting an
> > MPD with the current software does that.
>
> I did some testing. LDLite functions fine with subdirs in MPD filenames
> (ex:
> 0 FILE foo\bar\test.dat
> works fine, as long as any references to that file are
> 1 ... foo\bar\test.dat
> LDraw works fine with subdirs, as we already knew.
Awesome. That's so cool!
One question, though: Does it require backslashes or does it allow forward
slashes as well?
> The problems are with the MPD splitters. Jacob's MPD splitter works fine
> as long as the subdirectory already exists. However, in most cases, the
> subdir will *not* exist before splitting. Onyx's M-Peedy claims to have
> split the MPD correctly, but the files are nowhere to be found.
>
> Onyx and Jacob, is it possible to enhance your programs to correctly
> create subdirectories when an MPD has a path instead of just a filename
> after the 0 FILE marker?
It looks like I have the same bug in mpdgarp*. Fortunately, some OS's allow
the -p option on calls to the mkdir program:
-p Create intermediate directories as required. If this option is
not specified, the full path prefix of each operand must already
exist. Intermediate directories are created with permission bits
of rwxrwxrwx (0777) as modified by the current umask, plus write
and search permission for the owner.
So that's a Q&D way to fix it, but not a very platform-independent one.
It's easy enough, though, in any language/OS combination, to split a
filename on slash or backslash and call the language's built-in mkdir
function down the tree as needed. In raw Perl this might go something like:
:
# obtain filename (assume relative to current working directory)
:
my @dirs = split /[\/\\]/, $filename;
pop @dirs; # Remove filename, possibly leaving @dirs empty.
for (0..$#dirs)
{
$dirs[$_] ne ".." or die "$filename contains '..'";
my $path = join("/", @dirs[0..$_]);
next if -d $path;
-f $path and die "Regular file already exists at $path";
mkdir($path, 0777) or die "Couldn't create $path";
}
:
# write data to filename
:
--Todd
* http://www.lugnet.com/news/display.cgi?lugnet.cad.dev:212
|
|
Message has 1 Reply:
Message is in Reply To:
94 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|