Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 340826 - PublishHelper fails to 'move' file to a different device
Summary: PublishHelper fails to 'move' file to a different device
Status: NEW
Alias: None
Product: WTP ServerTools
Classification: WebTools
Component: wst.server (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: Future   Edit
Assignee: Angel Vera CLA
QA Contact: Angel Vera CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-23 21:41 EDT by tundra CLA
Modified: 2011-06-08 10:18 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tundra CLA 2011-03-23 21:41:45 EDT
Build Identifier: Version: 3.6.1 

Publish helper's approach to  moving files during publishing does not work when publishing to a path on a different device. The publish moves file from .metadata/.plugins/org.eclipse.jst.server.generic.core/tmp directory to a directory supplied in AbstractModuleAssembler.Factory .getModuleAssembler(module, getServer(), p);

The offending code is in PublishHelper.moveTempFile(File tempFile, File file) method.

 /**
   * Utility method to move a temp file into position by deleting the original and
   * swapping in a new copy.
   *
   * @param tempFile
   * @param file
   * @throws CoreException
   */
  private void moveTempFile(File tempFile, File file) throws CoreException
  {
    if (file.exists()) {
      if (!safeDelete(file, 2)) {
        // attempt to rewrite an existing file with the tempFile contents if
        // the existing file can't be deleted to permit the move
        try {
          InputStream in = new FileInputStream(tempFile);
          IStatus status = copyFile(in, file.getPath());
          if (!status.isOK()) {
            MultiStatus status2 = new MultiStatus(ServerPlugin.PLUGIN_ID,
                                                  0,
                                                  NLS.bind(Messages.errorDeleting,
                                                           file.toString()),
                                                  null);
            status2.add(status);
            throw new CoreException(status2);
          }
          return;
        } catch (FileNotFoundException e) {
          // shouldn't occur
        } finally {
          tempFile.delete();
        }
        /*if (!safeDelete(file, 8)) {
                                         tempFile.delete();
                                         throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, file.toString()), null));
                                 }*/
      }
    }
    if (!safeRename(tempFile, file, 10))
      throw new CoreException(new Status(IStatus.ERROR,
                                         ServerPlugin.PLUGIN_ID,
                                         0,
                                         NLS.bind(Messages.errorRename,
                                                  tempFile.toString()),
                                         null));
  }

Reproducible: Always

Steps to Reproduce:
1. Create a custom Publisher
2. In that publisher create an AbstractModuleAssembler using AbstractModuleAssembler.Factory          .getModuleAssembler(IModule module, GenericServer server, IPath path);
3. publish a webapp via Eclipse.
Comment 1 Rob Stryker CLA 2011-05-12 01:05:12 EDT
Hi Tundra:
  If you mean the class PublishHelper in org.eclipse.wst.server.core.util package, then this is a ServerTools bug and needs to be brought up there.

For what it's worth, I do remember that one way to properly fix this is to make sure your temporary file is on the same device and filesystem as your destination file. The PublishHelper class actually takes a temporary directory in it's constructor to allow you to do this. 

A stacktrace of the failure would definitely be helpful... It's possible there's a slight API deficiency for users looking to make use of this functionality, but after reviewing the code, I suspect all that you'd need to make use of is currently already available to you. 

Routing over to servertools
Comment 2 Angel Vera CLA 2011-05-12 15:50:51 EDT
I recall we had some problems around this area a few years ago. Not sure if we did fixed it or not.

Tim, 

Do you recall what happened to the moving/copy of files to a different device? Did we fixed it?

I will see if I can find the bug.
Comment 3 Tim deBoer CLA 2011-05-12 16:41:29 EDT
Rob is correct - it is the job of whoever creates the publish util/helper (looks like generic server in this case) to use a temp folder on the target device, typically relative or near to the final publishing folder. If the publish helper is created without a temp folder or not on the drive/device it is publishing to, we'd expect a failure like this on *nix.
Comment 4 Angel Vera CLA 2011-06-08 10:18:35 EDT
Moving out of 3.3 as we are almost done with it. Marking for future until we
have a more accurate time when we can work on this.