Exemple #1
0
  protected void revertFileName(TranscodeFileImpl tf) throws TranscodeException {

    File cache_file = tf.getCacheFile();

    if (cache_file.exists()) {

      Debug.out("Cache file already allocated, can't rename");

      return;
    }

    File source_file = tf.getSourceFile().getFile(true);

    String original_name = source_file.getName();

    int pos = original_name.indexOf('.');

    if (pos == -1) {

      return;
    }

    String cf_name = cache_file.getName();

    if (cf_name.endsWith(original_name.substring(pos))) {

      return;
    }

    try {
      synchronized (this) {
        if (device_files == null) {

          loadDeviceFile();
        }

        String reverted_name = allocateUniqueFileName(original_name);

        tf.setCacheFile(new File(cache_file.getParentFile(), reverted_name));
      }
    } catch (Throwable e) {

      throw (new TranscodeException("File name revertion failed", e));
    }
  }
Exemple #2
0
  protected void deleteFile(TranscodeFileImpl file, boolean delete_contents, boolean remove)
      throws TranscodeException {
    if (file.isDeleted()) {

      return;
    }

    if (delete_contents) {

      File f = file.getCacheFile();

      int time = 0;

      while (f.exists() && !f.delete()) {

        if (time > 3000) {

          log("Failed to remove file '" + f.getAbsolutePath() + "'");

          break;

        } else {

          try {
            Thread.sleep(500);

          } catch (Throwable e) {

          }

          time += 500;
        }
      }
    }

    if (remove) {

      try {
        // fire the listeners FIRST as this gives listeners a chance to extract data
        // from the file before it is deleted (otherwise operations fail with 'file has been
        // deleted'

        for (TranscodeTargetListener l : listeners) {

          try {
            l.fileRemoved(file);

          } catch (Throwable e) {

            Debug.out(e);
          }
        }

        synchronized (this) {
          if (device_files == null) {

            loadDeviceFile();

          } else {

            device_files_last_mod = SystemTime.getMonotonousTime();
          }

          device_files.remove(file.getKey());

          device_files_dirty = true;
        }

      } catch (Throwable e) {

        throw (new TranscodeException("Delete failed", e));
      }
    }
  }