|
From: Chris W. <la...@us...> - 2001-10-25 14:58:52
|
Update of /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Page
In directory usw-pr-cvs1:/tmp/cvs-serv22007/OpenInteract/Page
Modified Files:
Database.pm File.pm
Log Message:
deal with uploaded files
Index: Database.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Page/Database.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Database.pm 2001/10/24 23:04:14 1.3
--- Database.pm 2001/10/25 14:58:50 1.4
***************
*** 23,27 ****
my $page_content = eval { $self->page_content } || $R->page_content->new;
$page_content->{location} = $self->{location};
! $page_content->{content} = $content;
return $page_content->save;
}
--- 23,40 ----
my $page_content = eval { $self->page_content } || $R->page_content->new;
$page_content->{location} = $self->{location};
!
! if ( ! ref $content ) {
! $page_content->{content} = $content;
! }
!
! elsif ( ref $content eq 'SCALAR' ) {
! $page_content->{content} = $$content;
! }
!
! else {
! local $/ = undef;
! $page_content->{content} = <$content>;
! }
!
return $page_content->save;
}
Index: File.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Page/File.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** File.pm 2001/10/24 23:04:15 1.3
--- File.pm 2001/10/25 14:58:50 1.4
***************
*** 4,7 ****
--- 4,9 ----
use strict;
+ use File::Basename;
+ use File::Path;
# Use this to mark the beginning and end of the "good" content in a
***************
*** 64,69 ****
}
}
open( NEW, "> $tmp_location" ) || die "Cannot open temp file for writing: $!";
! print NEW $content;
close( NEW );
$R->DEBUG && $R->scrib( 1, "Wrote content to file ok." );
--- 66,94 ----
}
}
+
+ # Ensure the directory where this will go exists
+
+ _create_location_path( $full_location );
+
open( NEW, "> $tmp_location" ) || die "Cannot open temp file for writing: $!";
!
! $R->DEBUG && $R->scrib( 1, "Content isa: ", ref $content );
!
! if ( ! ref $content ) {
! print NEW $content;
! }
!
! elsif ( ref $content eq 'SCALAR' ) {
! print NEW $$content;
! }
!
! else {
! my ( $data );
! binmode $content;
! while ( read( $content, $data, 1024 ) ) {
! print NEW $data;
! }
! }
!
close( NEW );
$R->DEBUG && $R->scrib( 1, "Wrote content to file ok." );
***************
*** 99,102 ****
--- 124,147 ----
$R->DEBUG && $R->scrib( 1, "Trying to find filesystem location for ($html_dir) ($self->{location})" );
return join( '', $html_dir, $self->{location} );
+ }
+
+ sub _create_location_path {
+ my ( $location ) = @_;
+ my $R = OpenInteract::Request->instance;
+ $R->DEBUG && $R->scrib( 1, "See if ($location) exists or needs created" );
+
+ my $dirname = File::Basename::dirname( $location );
+ if ( -d $dirname ) {
+ $R->DEBUG && $R->scrib( 1, "Path for ($location) already exists" );
+ return 1;
+ }
+
+ eval { File::Path::mkpath( $dirname, undef, 0775 ) };
+ unless ( $@ ) {
+ $R->DEBUG && $R->scrib( 1, "Path for ($location) created ok" );
+ return 1;
+ }
+ $R->scrib( 0, "Cannot create path ($dirname): $@" );
+ die $@;
}
|