#!/usr/bin/perl # $Id: fetch.pm,v 1.5 2011/07/22 07:43:56 yason Exp $ package fetch; use db; use log; # bad! only for log::filelist() use warnings; #my $EXPAND_SYMLINKS = 1; my $QUERY_Z = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=0"; my $QUERY_P = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=1"; my $sth; my @stack_ids; # stack for ID's my @stack_paths;# stack for Path's my $tos = 0; # top of stack sub stack_push($$) { $stack_ids[$tos] = shift; $stack_paths[$tos] = shift; $tos++; } sub zayavki_list() { my @dbids; my @dbpaths; my @dbpri; my $i = 0; $sth = $db::dbh->prepare($QUERY_Z); $sth->execute( ); while( ($dbids[$i], $dbpaths[$i], $dbpri[$i]) = $sth->fetchrow_array( ) ) { if($dbids[$i]) # element exists (THIS CODE SHOULD BE FIXED) { #convert samba-paths to local unix paths $dbpaths[$i] = substr($dbpaths[$i], 13); # remove \\fileserver\ $dbpaths[$i] =~ tr/\\/\//; # convert each \ to / $dbpaths[$i] = '/mnt/maket/' . $dbpaths[$i]; $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) ); # # We must not save non-existent local file in array! # Returning of array with bad element is deprecated, # So this code too weak to work correctly. # # if($EXPAND_SYMLINKS && -e $dbpaths[$i]) # { # chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` ); # chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` ); # # # increment $i ONLY if local file exists, otherwise replace element in next iteration # $i++; # } # if localfile does not exists, write result of next iteration on its place } else { next; } } # strip last row in arrays by decrementing $i counter # SHOULD BE FIXED! $i--; $#dbids = $i; $#dbpaths = $i; # reformat listing using file_priority database field for($i = 0;$i < scalar(@dbids); $i++) { stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 0); } for($i = 0;$i < scalar(@dbids); $i++) { stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 1); } for($i = 0;$i < scalar(@dbids); $i++) { stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 2); } @dbids = @stack_ids; @dbpaths = @stack_paths; # make current files list via log::filelist() log::filelist(\@dbpaths); # we return the list of references to @dbids and @dbpaths return( (\@dbids, \@dbpaths) ); } sub probas_list() { my @dbids; my @dbpaths; my $i = 0; $sth = $db::dbh->prepare($QUERY_P); $sth->execute( ); while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) ) { $dbpaths[$i] = substr($dbpaths[$i], 13); $dbpaths[$i] =~ tr/\\/\//; $dbpaths[$i] = '/mnt/maket/' . $dbpaths[$i]; $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) ); # if($EXPAND_SYMLINKS && -e $dbpaths[$i]) # { # chomp( $_ = `dirname $dbpaths[$i] | xargs /usr/bin/readlink` ); # chomp( $dbpaths[$i] = $_ . '/' . `basename $dbpaths[$i]` ); # } $i++; } $i--; $#dbids = $i; $#dbpaths = $i; log::filelist(\@dbpaths); return( (\@dbids, \@dbpaths) ); } return(1);