Newer
Older
backup-commander / html / svc / file-line-reader.php
  1. <?php
  2.  
  3. /*
  4. * We only require reading output files during a test run for a client.
  5. * The backup thread does not delete test files because it is assumed that the client will
  6. * need the file contents during and after the test is complete.
  7. *
  8. */
  9. include_once "../shd/backup-funcs.php";
  10.  
  11. $open_files = array(); //files are indexed on their backup-id
  12.  
  13.  
  14. /*
  15. * Get or open a file reader. Returns null if the file does not exist.
  16. *
  17. * $dataLoc: the location of the file
  18. * $buid: the backup ID
  19. */
  20. function getObject_outputFile( $dataLoc, $buid ){
  21. global $open_files;
  22. if( !array_key_exists( $buid, $open_files) ){
  23. $fn = getFilename_out( $buid, true, false );
  24. $ffn = "$dataLoc/$fn";
  25. if( !file_exists( $ffn ) ) return null;
  26. $file = new SplFileObject( $ffn, 'r' );
  27. $open_files[ $buid ] = $file;
  28. }
  29. return $open_files[$buid];
  30.  
  31. }
  32.  
  33. function closeFile( $buid ){
  34.  
  35. global $open_files;
  36.  
  37. print("Closed output file for backup($buid)\n");
  38. if( !array_key_exists( $buid, $open_files) ) return 0;
  39. unset( $open_files[ $buid ] );
  40. }
  41.  
  42. /**
  43. * Return the file data starting from the $lineNum given.
  44. *
  45. * Return the number of lines read.
  46. *
  47. * $lineData: (out) Data as a single string.
  48. */
  49. function getLinesFrom( $objFile, $lineNum, &$lineData ){
  50.  
  51. $lineData = '';
  52. $cnt=0;
  53. $objFile->seek( $lineNum );
  54. while (!$objFile->eof()) {
  55. $cnt++;
  56. $lineData .= $objFile->fgets();
  57. }
  58. return $cnt;
  59. }
  60.  
  61. ?>