Exemple #1
0
  private OCFile obtainNewOCFileToUpload(
      String remotePath, String localPath, String mimeType, FileDataStorageManager storageManager) {
    OCFile newFile = new OCFile(remotePath);
    newFile.setStoragePath(localPath);
    newFile.setLastSyncDateForProperties(0);
    newFile.setLastSyncDateForData(0);

    // size
    if (localPath != null && localPath.length() > 0) {
      File localFile = new File(localPath);
      newFile.setFileLength(localFile.length());
      newFile.setLastSyncDateForData(localFile.lastModified());
    } // don't worry about not assigning size, the problems with localPath
    // are checked when the UploadFileOperation instance is created

    // MIME type
    if (mimeType == null || mimeType.length() <= 0) {
      try {
        mimeType =
            MimeTypeMap.getSingleton()
                .getMimeTypeFromExtension(remotePath.substring(remotePath.lastIndexOf('.') + 1));
      } catch (IndexOutOfBoundsException e) {
        Log_OC.e(TAG, "Trying to find out MIME type of a file without extension: " + remotePath);
      }
    }
    if (mimeType == null) {
      mimeType = "application/octet-stream";
    }
    newFile.setMimetype(mimeType);

    return newFile;
  }
Exemple #2
0
  /**
   * Saves a OC File after a successful upload.
   *
   * <p>A PROPFIND is necessary to keep the props in the local database synchronized with the
   * server, specially the modification time and Etag (where available)
   *
   * <p>TODO refactor this ugly thing
   */
  private void saveUploadedFile() {
    OCFile file = mCurrentUpload.getFile();
    if (file.fileExists()) {
      file = mStorageManager.getFileById(file.getFileId());
    }
    long syncDate = System.currentTimeMillis();
    file.setLastSyncDateForData(syncDate);

    // new PROPFIND to keep data consistent with server
    // in theory, should return the same we already have
    ReadRemoteFileOperation operation = new ReadRemoteFileOperation(mCurrentUpload.getRemotePath());
    RemoteOperationResult result = operation.execute(mUploadClient);
    if (result.isSuccess()) {
      updateOCFile(file, (RemoteFile) result.getData().get(0));
      file.setLastSyncDateForProperties(syncDate);
    }

    // / maybe this would be better as part of UploadFileOperation... or
    // maybe all this method
    if (mCurrentUpload.wasRenamed()) {
      OCFile oldFile = mCurrentUpload.getOldFile();
      if (oldFile.fileExists()) {
        oldFile.setStoragePath(null);
        mStorageManager.saveFile(oldFile);
      } // else: it was just an automatic renaming due to a name
      // coincidence; nothing else is needed, the storagePath is right
      // in the instance returned by mCurrentUpload.getFile()
    }

    mStorageManager.saveFile(file);
  }