public UniversalUniqueIdentifier addBlob(IFileStore target, boolean moveContents)
     throws CoreException {
   UniversalUniqueIdentifier uuid = new UniversalUniqueIdentifier();
   folderFor(uuid).mkdir(EFS.NONE, null);
   IFileStore destination = fileFor(uuid);
   if (moveContents) target.move(destination, EFS.NONE, null);
   else target.copy(destination, EFS.NONE, null);
   return uuid;
 }
Esempio n. 2
0
 /**
  * Completes a move after a file transfer. Returns <code>true</code> if the move was successful,
  * and <code>false</code> otherwise. In case of failure, this method handles setting an
  * appropriate response.
  */
 private boolean completeMove(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException {
   IPath destPath = new Path(getPath()).append(getFileName());
   try {
     IFileStore source = EFS.getStore(new File(getStorageDirectory(), FILE_DATA).toURI());
     IFileStore destination = NewFileServlet.getFileStore(destPath);
     source.move(destination, EFS.OVERWRITE, null);
   } catch (CoreException e) {
     String msg = NLS.bind("Failed to complete file transfer on {0}", destPath.toString());
     statusHandler.handleRequest(
         req,
         resp,
         new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e));
     return false;
   }
   return true;
 }
 /**
  * Perform a copy or move as specified by the request.
  *
  * @return <code>true</code> if the operation was successful, and <code>false</code> otherwise.
  */
 private boolean performCopyMove(
     HttpServletRequest request,
     HttpServletResponse response,
     JSONObject requestObject,
     IFileStore toCreate,
     boolean isCopy,
     int options)
     throws ServletException, CoreException {
   String locationString = requestObject.optString(ProtocolConstants.KEY_LOCATION, null);
   if (locationString == null) {
     statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR,
             HttpServletResponse.SC_BAD_REQUEST,
             "Copy or move request must specify source location",
             null));
     return false;
   }
   try {
     IFileStore source = resolveSourceLocation(request, locationString);
     if (source == null) {
       statusHandler.handleRequest(
           request,
           response,
           new ServerStatus(
               IStatus.ERROR,
               HttpServletResponse.SC_NOT_FOUND,
               NLS.bind("Source does not exist: ", locationString),
               null));
       return false;
     }
     boolean allowOverwrite = (options & CREATE_NO_OVERWRITE) == 0;
     int efsOptions = allowOverwrite ? EFS.OVERWRITE : EFS.NONE;
     try {
       if (isCopy) source.copy(toCreate, efsOptions, null);
       else source.move(toCreate, efsOptions, null);
     } catch (CoreException e) {
       if (!source.fetchInfo().exists()) {
         statusHandler.handleRequest(
             request,
             response,
             new ServerStatus(
                 IStatus.ERROR,
                 HttpServletResponse.SC_NOT_FOUND,
                 NLS.bind("Source does not exist: ", locationString),
                 e));
         return false;
       }
       if (e.getStatus().getCode() == EFS.ERROR_EXISTS) {
         statusHandler.handleRequest(
             request,
             response,
             new ServerStatus(
                 IStatus.ERROR,
                 HttpServletResponse.SC_PRECONDITION_FAILED,
                 "A file or folder with the same name already exists at this location",
                 null));
         return false;
       }
       // just rethrow if we can't do something more specific
       throw e;
     }
   } catch (URISyntaxException e) {
     statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR,
             HttpServletResponse.SC_BAD_REQUEST,
             NLS.bind("Bad source location in request: ", locationString),
             e));
     return false;
   }
   return true;
 }