Logo Search packages:      
Sourcecode: jlha-utils version File versions  Download package

void org::jlhafrontend::JLHAFrontEnd::update ( Opts  useropts,
String  archiveFilename,
String[]  filesFilename 
) [inline]

execute update command

Parameters:
useropts Options input by users
archiveFilename the filename of the archive file
filesFilename the array of filenames to be updated

Definition at line 524 of file JLHAFrontEnd.java.

References create(), createSwitcher(), genListArray(), list(), mkbackup(), mylogger, and transferBackupToArchive().

Referenced by start().

                                                                                      {
      String[] list;
      int i=0,j=0;
      File fl=null;
      String backupFilename=null;
      LhaFile backupFile=null;
      LhaHeader[] backupFileEntries=null;
      LhaOutputStream lio=null;
      Vector newlist;

      /* open archive file */
      try {
          fl = (new File(archiveFilename));
      } catch (Exception e) {
          mylogger.warning("Open "+archiveFilename+" error:"+e.toString());
          return;
      }

      /* if the file is not exist, call create */
      try {
          if (!fl.exists()) {
            create(useropts,archiveFilename,filesFilename);
            return;
          }
      } catch (SecurityException e) {
          mylogger.severe("Cannot test exist");
          return;
      }


      /* make backup */
      backupFilename = mkbackup(archiveFilename);

      /* open new archive file */
      try {
          lio = new LhaOutputStream(new FileOutputStream(archiveFilename));
      } catch (Exception e) {
          mylogger.severe("new LhaImeediateOutputStream with "+archiveFilename+" error: "+e.toString());
          return;
      }

      /* generate list */
      list = genListArray(filesFilename);

      /* open backup file */
      try {
          backupFile = new LhaFile (new File(backupFilename));
      } catch (FileNotFoundException e) {
          System.err.println("LHa: Fatal error: "+archiveFilename+": No such file or directory");
          return;
      } catch (Exception e) {
          mylogger.warning("Open "+archiveFilename+" error:"+e.toString());             System.err.println("LHa: Warning: Checksum error (LHarc file?)");
          System.err.println("LHa: Fatal error: Unkonwn header (lha file?)");
          return;
      }

      /* compare createtime */
      backupFileEntries = backupFile.getEntries();
      newlist = new Vector();
      for (i=0 ; i<list.length ; i++) {
          File f1;
          long modtime,oldmodtime;

          f1=null;
          modtime=0;
          oldmodtime=0;

          try {
            f1 = new File(list[i]);
            modtime = f1.lastModified();
          } catch (SecurityException e) {
              mylogger.warning("cannot get file modified time "+e.toString());
          }

          if (f1==null || f1.isDirectory()) {
            continue;
          }
          
          if (modtime==0) {
            newlist.add(list[i]);
            continue;
          }

          for (j=0 ; j<backupFileEntries.length ; j++) {
            if (backupFileEntries[j].getPath().equals(list[i])) {
                oldmodtime = backupFileEntries[j].getLastModified().getTime();
                break;
            }
          }

          if (oldmodtime == 0 || modtime > oldmodtime) {
            newlist.add(list[i]);
          }
          
      }

      list = new String[newlist.size()];
      for (i=0 ; i<newlist.size() ; i++) {
          list[i] = (String)newlist.elementAt(i);
      }

      transferBackupToArchive(backupFile,lio,list);

      /* compress new entries */
      for (i=0 ; i<list.length ; i++) {
          createSwitcher(useropts,lio,list[i]);
      }
      try {
          lio.close();
      } catch (IOException e) {
          mylogger.severe("lio.close() "+e.toString());
      }
      try {
          backupFile.close();
      } catch (IOException e) {
          mylogger.severe("backupFile.close() "+e.toString());
      }
      
    }


Generated by  Doxygen 1.6.0   Back to index