1 11 package org.eclipse.core.internal.resources; 12 13 import java.net.URI ; 14 import org.eclipse.core.filesystem.*; 15 import org.eclipse.core.internal.localstore.FileSystemResourceManager; 16 import org.eclipse.core.internal.properties.IPropertyManager; 17 import org.eclipse.core.internal.utils.Messages; 18 import org.eclipse.core.internal.utils.Policy; 19 import org.eclipse.core.resources.*; 20 import org.eclipse.core.resources.team.IResourceTree; 21 import org.eclipse.core.runtime.*; 22 import org.eclipse.core.runtime.jobs.ILock; 23 import org.eclipse.osgi.util.NLS; 24 25 34 class ResourceTree implements IResourceTree { 35 36 private boolean isValid = true; 37 private final FileSystemResourceManager localManager; 38 41 private ILock lock; 42 private MultiStatus multistatus; 43 private int updateFlags; 44 45 48 public ResourceTree(FileSystemResourceManager localManager, ILock lock, MultiStatus status, int updateFlags) { 49 super(); 50 this.localManager = localManager; 51 this.lock = lock; 52 this.multistatus = status; 53 this.updateFlags = updateFlags; 54 } 55 56 59 public void addToLocalHistory(IFile file) { 60 Assert.isLegal(isValid); 61 try { 62 lock.acquire(); 63 if (!file.exists()) 64 return; 65 IFileStore store = localManager.getStore(file); 66 final IFileInfo fileInfo = store.fetchInfo(); 67 if (!fileInfo.exists()) 68 return; 69 localManager.getHistoryStore().addState(file.getFullPath(), store, fileInfo, false); 70 } finally { 71 lock.release(); 72 } 73 } 74 75 private IFileStore computeDestinationStore(IProjectDescription destDescription) throws CoreException { 76 URI destLocation = destDescription.getLocationURI(); 77 if (destLocation == null) { 79 IPath rootLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation(); 80 destLocation = rootLocation.append(destDescription.getName()).toFile().toURI(); 81 } 82 return EFS.getStore(destLocation); 83 } 84 85 88 public long computeTimestamp(IFile file) { 89 Assert.isLegal(isValid); 90 try { 91 lock.acquire(); 92 if (!file.getProject().exists()) 93 return NULL_TIMESTAMP; 94 return internalComputeTimestamp(file); 95 } finally { 96 lock.release(); 97 } 98 } 99 100 106 private void copyLocalHistory(IResource source, IResource destination) { 107 localManager.getHistoryStore().copyHistory(source, destination, true); 108 } 109 110 113 public void deletedFile(IFile file) { 114 Assert.isLegal(isValid); 115 try { 116 lock.acquire(); 117 if (!file.exists()) 119 return; 120 try { 121 ((Resource) file).deleteResource(true, null); 123 } catch (CoreException e) { 124 String message = NLS.bind(Messages.resources_errorDeleting, file.getFullPath()); 125 IStatus status = new ResourceStatus(IStatus.ERROR, file.getFullPath(), message, e); 126 failed(status); 127 } 128 } finally { 129 lock.release(); 130 } 131 } 132 133 136 public void deletedFolder(IFolder folder) { 137 Assert.isLegal(isValid); 138 try { 139 lock.acquire(); 140 if (!folder.exists()) 142 return; 143 try { 144 ((Resource) folder).deleteResource(true, null); 146 } catch (CoreException e) { 147 String message = NLS.bind(Messages.resources_errorDeleting, folder.getFullPath()); 148 IStatus status = new ResourceStatus(IStatus.ERROR, folder.getFullPath(), message, e); 149 failed(status); 150 } 151 } finally { 152 lock.release(); 153 } 154 } 155 156 159 public void deletedProject(IProject target) { 160 Assert.isLegal(isValid); 161 try { 162 lock.acquire(); 163 if (!target.exists()) 165 return; 166 try { 168 ((Project) target).deleteResource(false, null); 169 } catch (CoreException e) { 170 String message = NLS.bind(Messages.resources_errorDeleting, target.getFullPath()); 171 IStatus status = new ResourceStatus(IStatus.ERROR, target.getFullPath(), message, e); 172 failed(status); 174 } 175 } finally { 176 lock.release(); 177 } 178 } 179 180 184 private boolean ensureDestinationEmpty(IProject source, IFileStore destinationStore, IProgressMonitor monitor) throws CoreException { 185 String message; 186 if (!destinationStore.fetchInfo().exists()) 188 return true; 189 if (destinationStore.childNames(EFS.NONE, Policy.subMonitorFor(monitor, 0)).length > 0) { 191 if (((Resource) source).getStore().equals(destinationStore)) 193 return true; 194 message = NLS.bind(Messages.localstore_resourceExists, destinationStore); 196 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, null); 197 failed(status); 198 return false; 199 } 200 destinationStore.delete(EFS.NONE, Policy.subMonitorFor(monitor, 0)); 202 return true; 203 } 204 205 209 public void failed(IStatus reason) { 210 Assert.isLegal(isValid); 211 multistatus.add(reason); 212 } 213 214 217 protected IStatus getStatus() { 218 return multistatus; 219 } 220 221 224 public long getTimestamp(IFile file) { 225 Assert.isLegal(isValid); 226 try { 227 lock.acquire(); 228 if (!file.exists()) 229 return NULL_TIMESTAMP; 230 ResourceInfo info = ((File) file).getResourceInfo(false, false); 231 return info == null ? NULL_TIMESTAMP : info.getLocalSyncInfo(); 232 } finally { 233 lock.release(); 234 } 235 } 236 237 243 private long internalComputeTimestamp(IFile file) { 244 IFileInfo fileInfo = localManager.getStore(file).fetchInfo(); 245 return fileInfo.exists() ? fileInfo.getLastModified() : NULL_TIMESTAMP; 246 } 247 248 252 private boolean internalDeleteFile(IFile file, int flags, IProgressMonitor monitor) { 253 try { 254 String message = NLS.bind(Messages.resources_deleting, file.getFullPath()); 255 monitor.beginTask(message, Policy.totalWork); 256 Policy.checkCanceled(monitor); 257 258 if (!file.exists()) { 260 return true; 262 } 263 if (file.isLinked()) { 265 deletedFile(file); 266 return true; 267 } 268 IFileStore fileStore = localManager.getStore(file); 271 boolean localExists = fileStore.fetchInfo().exists(); 272 if (!localExists) { 273 deletedFile(file); 274 return true; 276 } 277 278 boolean keepHistory = (flags & IResource.KEEP_HISTORY) != 0; 279 boolean force = (flags & IResource.FORCE) != 0; 280 281 if (keepHistory) 283 addToLocalHistory(file); 284 monitor.worked(Policy.totalWork / 4); 285 286 if (!force) { 289 boolean inSync = isSynchronized(file, IResource.DEPTH_ZERO); 290 if (!inSync && localExists) { 292 message = NLS.bind(Messages.localstore_resourceIsOutOfSync, file.getFullPath()); 293 IStatus status = new ResourceStatus(IResourceStatus.OUT_OF_SYNC_LOCAL, file.getFullPath(), message); 294 failed(status); 295 return false; 297 } 298 } 299 monitor.worked(Policy.totalWork / 4); 300 301 try { 303 fileStore.delete(EFS.NONE, Policy.subMonitorFor(monitor, Policy.totalWork / 4)); 304 deletedFile(file); 307 return true; 309 } catch (CoreException e) { 310 message = NLS.bind(Messages.resources_couldnotDelete, fileStore.toString()); 311 IStatus status = new ResourceStatus(IResourceStatus.FAILED_DELETE_LOCAL, file.getFullPath(), message, e); 312 failed(status); 313 } 314 return false; 316 } finally { 317 monitor.done(); 318 } 319 } 320 321 326 private boolean internalDeleteFolder(IFolder folder, int flags, IProgressMonitor monitor) { 327 String message = NLS.bind(Messages.resources_deleting, folder.getFullPath()); 328 monitor.beginTask("", Policy.totalWork); monitor.subTask(message); 330 Policy.checkCanceled(monitor); 331 332 if (!folder.exists()) 334 return true; 335 336 if (folder.isLinked()) { 338 deletedFolder(folder); 339 return true; 340 } 341 342 IFileStore fileStore = localManager.getStore(folder); 344 if (!fileStore.fetchInfo().exists()) { 345 deletedFolder(folder); 346 return true; 347 } 348 349 try { 350 localManager.delete(folder, flags, Policy.subMonitorFor(monitor, Policy.totalWork)); 352 } catch (CoreException ce) { 353 message = NLS.bind(Messages.localstore_couldnotDelete, folder.getFullPath()); 354 MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_DELETE_LOCAL, message, ce); 355 if (ce.getStatus() != null) 356 status.merge(ce.getStatus()); 357 failed(status); 358 return false; 359 } 360 return true; 361 } 362 363 366 private boolean internalDeleteProject(IProject project, int flags, IProgressMonitor monitor) { 367 368 IResource[] members = null; 370 try { 371 members = project.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS); 372 } catch (CoreException e) { 373 String message = NLS.bind(Messages.resources_errorMembers, project.getFullPath()); 374 IStatus status = new ResourceStatus(IStatus.ERROR, project.getFullPath(), message, e); 375 failed(status); 376 return false; 378 } 379 boolean deletedChildren = true; 380 for (int i = 0; i < members.length; i++) { 381 IResource child = members[i]; 382 switch (child.getType()) { 383 case IResource.FILE : 384 if (!IProjectDescription.DESCRIPTION_FILE_NAME.equals(child.getName())) 386 deletedChildren &= internalDeleteFile((IFile) child, flags, Policy.subMonitorFor(monitor, Policy.totalWork / members.length)); 387 break; 388 case IResource.FOLDER : 389 deletedChildren &= internalDeleteFolder((IFolder) child, flags, Policy.subMonitorFor(monitor, Policy.totalWork / members.length)); 390 break; 391 } 392 } 393 IFileStore projectStore = localManager.getStore(project); 394 if (!deletedChildren) 398 return false; 400 401 String [] children; 403 try { 404 children = projectStore.childNames(EFS.NONE, null); 405 } catch (CoreException e) { 406 children = new String [0]; 408 } 409 if (children.length != 1 || !IProjectDescription.DESCRIPTION_FILE_NAME.equals(children[0])) { 410 String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, project.getName()); 411 failed(new ResourceStatus(IResourceStatus.OUT_OF_SYNC_LOCAL, project.getFullPath(), message)); 412 return false; 413 } 414 415 IResource file = project.findMember(IProjectDescription.DESCRIPTION_FILE_NAME); 417 if (file == null) { 418 IFileStore dotProject = projectStore.getChild(IProjectDescription.DESCRIPTION_FILE_NAME); 420 try { 421 dotProject.delete(EFS.NONE, null); 422 } catch (CoreException e) { 423 failed(e.getStatus()); 424 } 425 } else { 426 boolean deletedProjectFile = internalDeleteFile((IFile) file, flags, Policy.monitorFor(null)); 427 if (!deletedProjectFile) { 428 String message = NLS.bind(Messages.resources_couldnotDelete, file.getFullPath()); 429 IStatus status = new ResourceStatus(IResourceStatus.FAILED_DELETE_LOCAL, file.getFullPath(), message); 430 failed(status); 431 return false; 433 } 434 } 435 436 try { 438 projectStore.delete(EFS.NONE, null); 439 deletedProject(project); 440 return true; 442 } catch (CoreException e) { 443 String message = NLS.bind(Messages.resources_couldnotDelete, projectStore.toString()); 444 IStatus status = new ResourceStatus(IResourceStatus.FAILED_DELETE_LOCAL, project.getFullPath(), message, e); 445 failed(status); 446 return false; 448 } 449 } 450 451 454 private boolean isContentChange(IProject project, IProjectDescription destDescription) { 455 IProjectDescription srcDescription = ((Project) project).internalGetDescription(); 456 URI srcLocation = srcDescription.getLocationURI(); 457 URI destLocation = destDescription.getLocationURI(); 458 if (srcLocation == null || destLocation == null) 459 return true; 460 return !srcLocation.equals(destLocation); 462 } 463 464 467 private boolean isNameChange(IProject project, IProjectDescription description) { 468 return !project.getName().equals(description.getName()); 469 } 470 471 474 public boolean isSynchronized(IResource resource, int depth) { 475 try { 476 lock.acquire(); 477 return localManager.isSynchronized(resource, depth); 478 } finally { 479 lock.release(); 480 } 481 } 482 483 488 void makeInvalid() { 489 this.isValid = false; 490 } 491 492 495 public void movedFile(IFile source, IFile destination) { 496 Assert.isLegal(isValid); 497 try { 498 lock.acquire(); 499 if (!source.exists()) 501 return; 502 if (destination.exists()) { 504 String message = NLS.bind(Messages.resources_mustNotExist, destination.getFullPath()); 505 IStatus status = new ResourceStatus(IStatus.ERROR, destination.getFullPath(), message); 506 failed(status); 508 } 509 510 IPropertyManager propertyManager = ((Resource) source).getPropertyManager(); 512 try { 513 propertyManager.copy(source, destination, IResource.DEPTH_ZERO); 514 propertyManager.deleteProperties(source, IResource.DEPTH_ZERO); 515 } catch (CoreException e) { 516 String message = NLS.bind(Messages.resources_errorPropertiesMove, source.getFullPath(), destination.getFullPath()); 517 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, e); 518 failed(status); 520 } 521 522 Workspace workspace = (Workspace) source.getWorkspace(); 524 try { 525 workspace.move((Resource) source, destination.getFullPath(), IResource.DEPTH_ZERO, updateFlags, false); 526 } catch (CoreException e) { 527 String message = NLS.bind(Messages.resources_errorMoving, source.getFullPath(), destination.getFullPath()); 528 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, e); 529 failed(status); 531 } 532 533 try { 535 workspace.getMarkerManager().moved(source, destination, IResource.DEPTH_ZERO); 536 } catch (CoreException e) { 537 String message = NLS.bind(Messages.resources_errorMarkersDelete, source.getFullPath()); 538 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, e); 539 failed(status); 540 } 541 542 copyLocalHistory(source, destination); 544 } finally { 545 lock.release(); 546 } 547 } 548 549 552 public void movedFolderSubtree(IFolder source, IFolder destination) { 553 Assert.isLegal(isValid); 554 try { 555 lock.acquire(); 556 if (!source.exists()) 558 return; 559 if (destination.exists()) { 561 String message = NLS.bind(Messages.resources_mustNotExist, destination.getFullPath()); 562 IStatus status = new ResourceStatus(IStatus.ERROR, destination.getFullPath(), message); 563 failed(status); 564 return; 565 } 566 567 int depth = IResource.DEPTH_INFINITE; 569 IPropertyManager propertyManager = ((Resource) source).getPropertyManager(); 570 try { 571 propertyManager.copy(source, destination, depth); 572 propertyManager.deleteProperties(source, depth); 573 } catch (CoreException e) { 574 String message = NLS.bind(Messages.resources_errorPropertiesMove, source.getFullPath(), destination.getFullPath()); 575 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, e); 576 failed(status); 578 } 579 580 Workspace workspace = (Workspace) source.getWorkspace(); 582 try { 583 workspace.move((Resource) source, destination.getFullPath(), depth, updateFlags, false); 584 } catch (CoreException e) { 585 String message = NLS.bind(Messages.resources_errorMoving, source.getFullPath(), destination.getFullPath()); 586 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, e); 587 failed(status); 589 } 590 591 try { 593 workspace.getMarkerManager().moved(source, destination, depth); 594 } catch (CoreException e) { 595 String message = NLS.bind(Messages.resources_errorMarkersDelete, source.getFullPath()); 596 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, e); 597 failed(status); 598 } 599 600 copyLocalHistory(source, destination); 602 } finally { 603 lock.release(); 604 } 605 } 606 607 610 public boolean movedProjectSubtree(IProject project, IProjectDescription destDescription) { 611 Assert.isLegal(isValid); 612 try { 613 lock.acquire(); 614 if (!project.exists()) 616 return true; 617 618 Project source = (Project) project; 619 Project destination = (Project) source.getWorkspace().getRoot().getProject(destDescription.getName()); 620 Workspace workspace = (Workspace) source.getWorkspace(); 621 int depth = IResource.DEPTH_INFINITE; 622 623 if (isNameChange(source, destDescription)) { 626 if (destination.exists()) { 627 String message = NLS.bind(Messages.resources_mustNotExist, destination.getFullPath()); 628 IStatus status = new ResourceStatus(IStatus.ERROR, destination.getFullPath(), message); 629 failed(status); 630 return false; 631 } 632 633 try { 635 source.getPropertyManager().closePropertyStore(source); 636 localManager.getHistoryStore().closeHistoryStore(source); 637 } catch (CoreException e) { 638 String message = NLS.bind(Messages.properties_couldNotClose, source.getFullPath()); 639 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, e); 640 failed(status); 642 } 643 final IFileSystem fileSystem = EFS.getLocalFileSystem(); 644 IFileStore oldMetaArea = fileSystem.getStore(workspace.getMetaArea().locationFor(source)); 645 IFileStore newMetaArea = fileSystem.getStore(workspace.getMetaArea().locationFor(destination)); 646 try { 647 oldMetaArea.move(newMetaArea, EFS.NONE, new NullProgressMonitor()); 648 } catch (CoreException e) { 649 String message = NLS.bind(Messages.resources_moveMeta, oldMetaArea, newMetaArea); 650 IStatus status = new ResourceStatus(IResourceStatus.FAILED_WRITE_METADATA, destination.getFullPath(), message, e); 651 failed(status); 653 } 654 655 try { 657 workspace.move(source, destination.getFullPath(), depth, updateFlags, true); 658 } catch (CoreException e) { 659 String message = NLS.bind(Messages.resources_errorMoving, source.getFullPath(), destination.getFullPath()); 660 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, e); 661 failed(status); 663 } 664 665 ((ProjectInfo) destination.getResourceInfo(false, true)).fixupAfterMove(); 667 668 try { 670 workspace.getMarkerManager().moved(source, destination, depth); 671 } catch (CoreException e) { 672 String message = NLS.bind(Messages.resources_errorMarkersMove, source.getFullPath(), destination.getFullPath()); 673 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, e); 674 failed(status); 676 } 677 copyLocalHistory(source, destination); 679 } 680 681 try { 683 ((ProjectDescription) destDescription).setLinkDescriptions(destination.internalGetDescription().getLinks()); 685 destination.internalSetDescription(destDescription, true); 686 destination.writeDescription(IResource.FORCE); 687 } catch (CoreException e) { 688 String message = Messages.resources_projectDesc; 689 IStatus status = new ResourceStatus(IStatus.ERROR, destination.getFullPath(), message, e); 690 failed(status); 691 } 692 693 try { 695 workspace.getMetaArea().writePrivateDescription(destination); 696 } catch (CoreException e) { 697 failed(e.getStatus()); 698 } 699 700 try { 702 destination.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); 703 } catch (CoreException e) { 704 String message = NLS.bind(Messages.resources_errorRefresh, destination.getFullPath()); 705 IStatus status = new ResourceStatus(IStatus.ERROR, destination.getFullPath(), message, e); 706 failed(status); 707 return false; 708 } 709 return true; 710 } finally { 711 lock.release(); 712 } 713 } 714 715 719 private void moveProjectContent(IProject source, IFileStore destStore, int flags, IProgressMonitor monitor) throws CoreException { 720 try { 721 String message = NLS.bind(Messages.resources_moving, source.getFullPath()); 722 monitor.beginTask(message, 10); 723 IProjectDescription srcDescription = source.getDescription(); 724 URI srcLocation = srcDescription.getLocationURI(); 725 if (srcLocation != null && URIUtil.equals(srcLocation, destStore.toURI())) 727 return; 728 729 boolean replace = (flags & IResource.REPLACE) != 0; 731 if (replace) { 732 destStore.mkdir(EFS.NONE, Policy.subMonitorFor(monitor, 10)); 733 return; 734 } 735 736 localManager.move(source, destStore, flags, Policy.subMonitorFor(monitor, 9)); 738 739 if ((flags & IResource.SHALLOW) == 0) { 741 IResource[] children = source.members(); 742 for (int i = 0; i < children.length; i++) { 743 if (children[i].isLinked()) { 744 message = NLS.bind(Messages.resources_moving, children[i].getFullPath()); 745 monitor.subTask(message); 746 IFileStore linkDestination = destStore.getChild(children[i].getName()); 747 try { 748 localManager.move(children[i], linkDestination, flags, Policy.monitorFor(null)); 749 } catch (CoreException ce) { 750 failed(ce.getStatus()); 752 } 753 } 754 } 755 } 756 monitor.worked(1); 757 } finally { 758 monitor.done(); 759 } 760 } 761 762 765 public void standardDeleteFile(IFile file, int flags, IProgressMonitor monitor) { 766 Assert.isLegal(isValid); 767 try { 768 lock.acquire(); 769 internalDeleteFile(file, flags, monitor); 770 } finally { 771 lock.release(); 772 } 773 } 774 775 778 public void standardDeleteFolder(IFolder folder, int flags, IProgressMonitor monitor) { 779 Assert.isLegal(isValid); 780 try { 781 lock.acquire(); 782 internalDeleteFolder(folder, flags, monitor); 783 } finally { 784 lock.release(); 785 monitor.done(); 786 } 787 } 788 789 792 public void standardDeleteProject(IProject project, int flags, IProgressMonitor monitor) { 793 Assert.isLegal(isValid); 794 try { 795 lock.acquire(); 796 String message = NLS.bind(Messages.resources_deleting, project.getFullPath()); 797 monitor.beginTask(message, Policy.totalWork); 798 if (!project.exists()) 800 return; 801 802 boolean alwaysDeleteContent = (flags & IResource.ALWAYS_DELETE_PROJECT_CONTENT) != 0; 803 if (alwaysDeleteContent) 805 flags |= IResource.FORCE; 806 boolean force = (flags & IResource.FORCE) != 0; 807 boolean neverDeleteContent = (flags & IResource.NEVER_DELETE_PROJECT_CONTENT) != 0; 808 boolean success = true; 809 810 if (alwaysDeleteContent || (project.isOpen() && !neverDeleteContent)) { 814 if (!force && !isSynchronized(project, IResource.DEPTH_INFINITE)) { 819 success = internalDeleteProject(project, flags, monitor); 821 if (!success) { 822 IFileStore store = localManager.getStore(project); 823 message = NLS.bind(Messages.resources_couldnotDelete, store.toString()); 824 IStatus status = new ResourceStatus(IResourceStatus.FAILED_DELETE_LOCAL, project.getFullPath(), message); 825 failed(status); 826 } 827 return; 828 } 829 830 try { 831 IFileStore projectStore = localManager.getStore(project); 832 if (project.isOpen()) { 834 localManager.delete(project, flags & IResource.FORCE, Policy.subMonitorFor(monitor, Policy.totalWork * 7 / 8)); 836 } else { 837 projectStore.delete(EFS.NONE, Policy.subMonitorFor(monitor, Policy.totalWork * 7 / 8)); 838 } 839 } catch (CoreException ce) { 840 message = NLS.bind(Messages.localstore_couldnotDelete, project.getFullPath()); 841 MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_DELETE_LOCAL, message, ce); 842 if (ce.getStatus() != null) 843 status.merge(ce.getStatus()); 844 failed(status); 845 return; 846 } 847 } 848 849 if (success) 851 deletedProject(project); 852 else { 853 message = NLS.bind(Messages.localstore_couldnotDelete, project.getFullPath()); 854 IStatus status = new ResourceStatus(IResourceStatus.FAILED_DELETE_LOCAL, project.getFullPath(), message); 855 failed(status); 856 } 857 } finally { 858 lock.release(); 859 monitor.done(); 860 } 861 } 862 863 866 public void standardMoveFile(IFile source, IFile destination, int flags, IProgressMonitor monitor) { 867 Assert.isLegal(isValid); 868 try { 869 lock.acquire(); 870 String message = NLS.bind(Messages.resources_moving, source.getFullPath()); 871 monitor.subTask(message); 872 873 if (!source.exists() || destination.exists() || !destination.getParent().isAccessible()) 875 throw new IllegalArgumentException (); 876 877 boolean force = (flags & IResource.FORCE) != 0; 878 boolean keepHistory = (flags & IResource.KEEP_HISTORY) != 0; 879 boolean isDeep = (flags & IResource.SHALLOW) == 0; 880 881 if (!force && !isSynchronized(source, IResource.DEPTH_INFINITE)) { 884 message = NLS.bind(Messages.localstore_resourceIsOutOfSync, source.getFullPath()); 885 IStatus status = new ResourceStatus(IResourceStatus.OUT_OF_SYNC_LOCAL, source.getFullPath(), message); 886 failed(status); 887 return; 888 } 889 monitor.worked(Policy.totalWork / 4); 890 891 if (keepHistory) 893 addToLocalHistory(source); 894 monitor.worked(Policy.totalWork / 4); 895 896 if (!isDeep && source.isLinked()) { 898 movedFile(source, destination); 899 return; 900 } 901 902 IFileStore destStore = null; 905 boolean failedDeletingSource = false; 906 try { 907 destStore = localManager.getStore(destination); 908 destStore.getParent().mkdir(EFS.NONE, Policy.subMonitorFor(monitor, 0)); 910 localManager.move(source, destStore, flags, monitor); 911 } catch (CoreException e) { 912 failed(e.getStatus()); 913 failedDeletingSource = destStore != null && destStore.fetchInfo().exists(); 915 if (!failedDeletingSource) 917 return; 918 } 919 movedFile(source, destination); 920 updateMovedFileTimestamp(destination, internalComputeTimestamp(destination)); 921 if (failedDeletingSource) { 922 try { 924 source.refreshLocal(IResource.DEPTH_INFINITE, null); 925 } catch (CoreException e) { 926 } 928 } 929 monitor.worked(Policy.totalWork / 4); 930 return; 931 } finally { 932 lock.release(); 933 monitor.done(); 934 } 935 } 936 937 940 public void standardMoveFolder(IFolder source, IFolder destination, int flags, IProgressMonitor monitor) { 941 Assert.isLegal(isValid); 942 try { 943 lock.acquire(); 944 String message = NLS.bind(Messages.resources_moving, source.getFullPath()); 945 monitor.beginTask(message, 100); 946 947 if (!source.exists() || destination.exists() || !destination.getParent().isAccessible()) 949 throw new IllegalArgumentException (); 950 951 boolean force = (flags & IResource.FORCE) != 0; 955 if (!force && !isSynchronized(source, IResource.DEPTH_INFINITE)) { 956 message = NLS.bind(Messages.localstore_resourceIsOutOfSync, source.getFullPath()); 957 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message); 958 failed(status); 959 return; 960 } 961 monitor.worked(20); 962 963 boolean isDeep = (flags & IResource.SHALLOW) == 0; 965 if (!isDeep && source.isLinked()) { 966 movedFolderSubtree(source, destination); 967 return; 968 } 969 970 IFileStore destStore = null; 973 boolean failedDeletingSource = false; 974 try { 975 destStore = localManager.getStore(destination); 976 localManager.move(source, destStore, flags, Policy.subMonitorFor(monitor, 60)); 977 } catch (CoreException e) { 978 failed(e.getStatus()); 979 failedDeletingSource = destStore != null && destStore.fetchInfo().exists(); 981 if (!failedDeletingSource) 983 return; 984 } 985 movedFolderSubtree(source, destination); 986 monitor.worked(20); 987 updateTimestamps(destination, isDeep); 988 if (failedDeletingSource) { 989 try { 991 source.refreshLocal(IResource.DEPTH_INFINITE, null); 992 destination.refreshLocal(IResource.DEPTH_INFINITE, null); 993 } catch (CoreException e) { 994 } 996 } 997 } finally { 998 lock.release(); 999 monitor.done(); 1000 } 1001 } 1002 1003 1006 public void standardMoveProject(IProject source, IProjectDescription description, int flags, IProgressMonitor monitor) { 1007 Assert.isLegal(isValid); 1008 try { 1009 lock.acquire(); 1010 String message = NLS.bind(Messages.resources_moving, source.getFullPath()); 1011 monitor.beginTask(message, Policy.totalWork); 1012 1013 if (!source.isAccessible()) 1015 throw new IllegalArgumentException (); 1016 1017 if (!isContentChange(source, description)) { 1020 movedProjectSubtree(source, description); 1021 return; 1022 } 1023 1024 boolean force = (flags & IResource.FORCE) != 0; 1026 if (!force && !isSynchronized(source, IResource.DEPTH_INFINITE)) { 1027 message = NLS.bind(Messages.localstore_resourceIsOutOfSync, source.getFullPath()); 1029 IStatus status = new ResourceStatus(IResourceStatus.OUT_OF_SYNC_LOCAL, source.getFullPath(), message); 1030 failed(status); 1031 return; 1032 } 1033 1034 IFileStore destinationStore; 1035 try { 1036 destinationStore = computeDestinationStore(description); 1037 if ((flags & IResource.REPLACE) == 0) 1039 if (!ensureDestinationEmpty(source, destinationStore, monitor)) 1040 return; 1041 } catch (CoreException e) { 1042 message = NLS.bind(Messages.localstore_couldNotMove, source.getFullPath()); 1044 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, e); 1045 failed(status); 1046 return; 1047 } 1048 1049 try { 1051 moveProjectContent(source, destinationStore, flags, Policy.subMonitorFor(monitor, Policy.totalWork * 3 / 4)); 1052 } catch (CoreException e) { 1053 message = NLS.bind(Messages.localstore_couldNotMove, source.getFullPath()); 1054 IStatus status = new ResourceStatus(IStatus.ERROR, source.getFullPath(), message, e); 1055 failed(status); 1056 try { 1058 source.refreshLocal(IResource.DEPTH_INFINITE, null); 1059 } catch (CoreException e2) { 1060 } 1062 } 1063 1064 movedProjectSubtree(source, description); 1067 monitor.worked(Policy.totalWork * 1 / 8); 1068 1069 boolean isDeep = (flags & IResource.SHALLOW) == 0; 1070 updateTimestamps(source.getWorkspace().getRoot().getProject(description.getName()), isDeep); 1071 monitor.worked(Policy.totalWork * 1 / 8); 1072 } finally { 1073 lock.release(); 1074 monitor.done(); 1075 } 1076 } 1077 1078 1081 public void updateMovedFileTimestamp(IFile file, long timestamp) { 1082 Assert.isLegal(isValid); 1083 try { 1084 lock.acquire(); 1085 if (!file.exists()) 1087 return; 1088 ResourceInfo info = ((Resource) file).getResourceInfo(false, true); 1090 localManager.updateLocalSync(info, timestamp); 1092 info.clear(ICoreConstants.M_LINK); 1094 } finally { 1095 lock.release(); 1096 } 1097 } 1098 1099 1103 private void updateTimestamps(IResource root, final boolean isDeep) { 1104 IResourceVisitor visitor = new IResourceVisitor() { 1105 public boolean visit(IResource resource) { 1106 if (resource.isLinked()) { 1107 if (isDeep) { 1108 ResourceInfo info = ((Resource) resource).getResourceInfo(false, true); 1110 info.clear(ICoreConstants.M_LINK); 1111 } 1112 return true; 1113 } 1114 return true; 1120 } 1121 }; 1122 try { 1123 root.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS); 1124 } catch (CoreException e) { 1125 } 1127 } 1128} 1129 | Popular Tags |