File.pl

From Organic Design
Jump to: navigation, search
Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.

<perl>

  1. Return content of passed file

sub readFile { my $file = shift; if ( open FH, '<', $file ) { binmode FH; sysread FH, ( my $out ), -s $file; close FH; return $out; } }

  1. Write passed content to passed file

sub writeFile { my $file = shift; if ( open FH, '>', $file ) { binmode FH; print FH shift; close FH; return $file; } }

  1. Sync local files with articles on local wiki

sub fileSync {

wikiLogin( $::wiki, $::peer, $::pwd1 ); my $updated = 0; my $udfile;

# todo: this should be using %{ links:anchors } = wikiGetList( $::wiki, "$peer/fileSync" )

for ( split /\n/, wikiRawPage( $::wiki, "$peer/fileSync" ) ) {

# Don't allow fileSync to pathnames for now if ( /^\*\s*\[*([^\]\|]+)(\|([^\]]+))?\]*/ ) { my $page = $1; my $file = ( $3 or $1 ); my $wikiContent = wikiRawPage( $::wiki, $page ); $wikiContent .= "\n" if $page =~ /\.[hc]$/i; my $fileContent = readFile( $file ); if ( $fileContent ne $wikiContent ) { logAdd "updating localFS \"$file\""; writeFile( $file, $wikiContent ); $updated++; $udfile = "$file"; } }

}

# Log summary on local wiki if any updated if ( $updated ) { my $comment = ($updated-1) ? "$updated articles" : $udfile; $comment .= ' updated on local FS'; wikiPageAppend( $::wiki, $::wikilog, "\n*".localtime()." : $comment", $comment ); }

logAdd 'Exit'; } </perl>