@Override public VirtualFile copy(final Object requestor, @NotNull final VirtualFile newParent, @NotNull final String copyName) throws IOException { if (getFileSystem() != newParent.getFileSystem()) { throw new IOException(VfsBundle.message("file.copy.error", newParent.getPresentableUrl())); } if (!newParent.isDirectory()) { throw new IOException(VfsBundle.message("file.copy.target.must.be.directory")); } return EncodingRegistry.doActionAndRestoreEncoding(this, new ThrowableComputable<VirtualFile, IOException>() { @Override public VirtualFile compute() throws IOException { return ourPersistence.copyFile(requestor, VirtualFileSystemEntry.this, newParent, copyName); } }); }
@NotNull private File copyToMirror(@NotNull File original, @NotNull File mirror) { ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); if (progress != null) { progress.pushState(); progress.setText(VfsBundle.message("jar.copy.progress", original.getPath())); progress.setFraction(0); } try { FileUtil.copy(original, mirror); } catch (final IOException e) { reportIOErrorWithJars(original, mirror, e); return original; } if (progress != null) { progress.popState(); } return mirror; }
@Nonnull private File copyToMirror(@Nonnull File original, @Nonnull File mirror) { ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); if (progress != null) { progress.pushState(); progress.setText(VfsBundle.message("jar.copy.progress", original.getPath())); progress.setFraction(0); } try { FileUtil.copy(original, mirror); } catch (final IOException e) { reportIOErrorWithJars(original, mirror, e); return original; } finally { if (progress != null) { progress.popState(); } } return mirror; }
@Override public void rename(final Object requestor, @NotNull @NonNls final String newName) throws IOException { if (getName().equals(newName)) return; if (!isValidName(newName)) { throw new IOException(VfsBundle.message("file.invalid.name.error", newName)); } ourPersistence.renameFile(requestor, this, newName); }
@Override public void move(final Object requestor, @NotNull final VirtualFile newParent) throws IOException { if (getFileSystem() != newParent.getFileSystem()) { throw new IOException(VfsBundle.message("file.move.error", newParent.getPresentableUrl())); } EncodingRegistry.doActionAndRestoreEncoding(this, new ThrowableComputable<VirtualFile, IOException>() { @Override public VirtualFile compute() throws IOException { ourPersistence.moveFile(requestor, VirtualFileSystemEntry.this, newParent); return VirtualFileSystemEntry.this; } }); }
public void setNewName(@NotNull String newName) { if (!isValidName(newName)) { throw new IllegalArgumentException(VfsBundle.message("file.invalid.name.error", newName)); } VirtualDirectoryImpl parent = getParent(); parent.removeChild(this); mySegment.setNameId(myId, FileNameCache.storeName(newName)); ((PersistentFSImpl)PersistentFS.getInstance()).incStructuralModificationCount(); parent.addChild(this); }
private void reportIOErrorWithJars(File original, File target, IOException e) { LOG.warn(e); String path = original.getPath(); myFileSystem.setNoCopyJarForPath(path); String message = VfsBundle.message("jar.copy.error.message", path, target.getPath(), e.getMessage()); ERROR_COPY_NOTIFICATION.getValue().createNotification(message, NotificationType.ERROR).notify(null); }
@Override public void startDownloading() { LOG.debug("Downloading requested"); File localFile; synchronized (myLock) { if (myState != RemoteFileState.DOWNLOADING_NOT_STARTED) { LOG.debug("File already downloaded: file = " + myLocalVirtualFile + ", state = " + myState); return; } myState = RemoteFileState.DOWNLOADING_IN_PROGRESS; try { myLocalFile = myManager.getStorage().createLocalFile(myUrl); LOG.debug("Local file created: " + myLocalFile.getAbsolutePath()); } catch (IOException e) { LOG.info(e); errorOccurred(VfsBundle.message("cannot.create.local.file", e.getMessage()), false); return; } myCancelled.set(false); localFile = myLocalFile; } for (FileDownloadingListener listener : myListeners) { listener.downloadingStarted(); } if (myContentProvider == null) { myContentProvider = myManager.findContentProvider(myUrl); } myContentProvider.saveContent(myUrl, localFile, this); }
private void reportIOErrorWithJars(File original, File mirror, IOException e) { LOG.warn(e); final String path = original.getPath(); final String message = VfsBundle.message("jar.copy.error.message", path, mirror.getPath(), e.getMessage()); ERROR_COPY_NOTIFICATION.getValue().createNotification(message, NotificationType.ERROR).notify(null); myFileSystem.setNoCopyJarForPath(path); }
@Override public void checkSetName(String name) throws IncorrectOperationException { //CheckUtil.checkIsIdentifier(name); CheckUtil.checkWritable(this); VirtualFile parentFile = myFile.getParent(); if (parentFile == null) { throw new IncorrectOperationException(VfsBundle.message("cannot.rename.root.directory")); } VirtualFile child = parentFile.findChild(name); if (child != null && !child.equals(myFile)) { throw new IncorrectOperationException(VfsBundle.message("file.already.exists.error", child.getPresentableUrl())); } }
@Override public void checkCreateSubdirectory(@NotNull String name) throws IncorrectOperationException { // TODO : another check? //CheckUtil.checkIsIdentifier(name); VirtualFile existingFile = getVirtualFile().findChild(name); if (existingFile != null) { throw new IncorrectOperationException(VfsBundle.message("file.already.exists.error", existingFile.getPresentableUrl())); } CheckUtil.checkWritable(this); }
@Override public void checkCreateFile(@NotNull String name) throws IncorrectOperationException { VirtualFile existingFile = getVirtualFile().findChild(name); if (existingFile != null) { throw new IncorrectOperationException(VfsBundle.message("file.already.exists.error", existingFile.getPresentableUrl())); } CheckUtil.checkWritable(this); }
@Override public VirtualFile copy(final Object requestor, @Nonnull final VirtualFile newParent, @Nonnull final String copyName) throws IOException { if (getFileSystem() != newParent.getFileSystem()) { throw new IOException(VfsBundle.message("file.copy.error", newParent.getPresentableUrl())); } if (!newParent.isDirectory()) { throw new IOException(VfsBundle.message("file.copy.target.must.be.directory")); } return EncodingRegistry.doActionAndRestoreEncoding(this, () -> ourPersistence.copyFile(requestor, this, newParent, copyName)); }
@Override public void move(final Object requestor, @Nonnull final VirtualFile newParent) throws IOException { if (getFileSystem() != newParent.getFileSystem()) { throw new IOException(VfsBundle.message("file.move.error", newParent.getPresentableUrl())); } EncodingRegistry.doActionAndRestoreEncoding(this, () -> { ourPersistence.moveFile(requestor, this, newParent); return this; }); }
public void setNewName(@Nonnull String newName) { if (!getFileSystem().isValidName(newName)) { throw new IllegalArgumentException(VfsBundle.message("file.invalid.name.error", newName)); } VirtualDirectoryImpl parent = getParent(); parent.removeChild(this); mySegment.setNameId(myId, FileNameCache.storeName(newName)); ((PersistentFSImpl)PersistentFS.getInstance()).incStructuralModificationCount(); parent.addChild(this); }
public void startDownloading() { LOG.debug("Downloading requested"); File localFile; synchronized (myLock) { if (myState != RemoteFileState.DOWNLOADING_NOT_STARTED) { LOG.debug("File already downloaded: file = " + myLocalVirtualFile + ", state = " + myState); return; } myState = RemoteFileState.DOWNLOADING_IN_PROGRESS; try { myLocalFile = myManager.getStorage().createLocalFile(myUrl); LOG.debug("Local file created: " + myLocalFile.getAbsolutePath()); } catch (IOException e) { LOG.info(e); errorOccurred(VfsBundle.message("cannot.create.local.file", e.getMessage()), false); return; } myCancelled.set(false); localFile = myLocalFile; } for (FileDownloadingListener listener : myListeners) { listener.downloadingStarted(); } if (myContentProvider == null) { myContentProvider = myManager.findContentProvider(myUrl); } myContentProvider.saveContent(myUrl, localFile, this); }
@Override public void checkCreateSubdirectory(@Nonnull String name) throws IncorrectOperationException { // TODO : another check? //CheckUtil.checkIsIdentifier(name); VirtualFile existingFile = getVirtualFile().findChild(name); if (existingFile != null) { throw new IncorrectOperationException(VfsBundle.message("file.already.exists.error", existingFile.getPresentableUrl())); } CheckUtil.checkWritable(this); }
@Override public void checkCreateFile(@Nonnull String name) throws IncorrectOperationException { VirtualFile existingFile = getVirtualFile().findChild(name); if (existingFile != null) { throw new IncorrectOperationException(VfsBundle.message("file.already.exists.error", existingFile.getPresentableUrl())); } for (PsiDirectoryMethodProxy proxy : PsiDirectoryMethodProxy.EP_NAME.getExtensions()) { if(!proxy.checkCreateFile(this, name)) { return; } } CheckUtil.checkWritable(this); }
@NotNull @Override public VirtualFile copyFile(Object requestor, @NotNull VirtualFile file, @NotNull VirtualFile newParent, @NotNull String copyName) throws IOException { throw new IOException(VfsBundle.message("jar.modification.not.supported.error", file.getUrl())); }
@NotNull @Override public VirtualFile createChildDirectory(Object requestor, @NotNull VirtualFile parent, @NotNull String dir) throws IOException { throw new IOException(VfsBundle.message("jar.modification.not.supported.error", parent.getUrl())); }
@NotNull @Override public VirtualFile createChildFile(Object requestor, @NotNull VirtualFile parent, @NotNull String file) throws IOException { throw new IOException(VfsBundle.message("jar.modification.not.supported.error", parent.getUrl())); }
@Override public void deleteFile(Object requestor, @NotNull VirtualFile file) throws IOException { throw new IOException(VfsBundle.message("jar.modification.not.supported.error", file.getUrl())); }
@Override public void moveFile(Object requestor, @NotNull VirtualFile file, @NotNull VirtualFile newParent) throws IOException { throw new IOException(VfsBundle.message("jar.modification.not.supported.error", file.getUrl())); }
@Override public void renameFile(Object requestor, @NotNull VirtualFile file, @NotNull String newName) throws IOException { throw new IOException(VfsBundle.message("jar.modification.not.supported.error", file.getUrl())); }
@Override public void setTimeStamp(@NotNull VirtualFile file, long timeStamp) throws IOException { throw new IOException(VfsBundle.message("jar.modification.not.supported.error", file.getUrl())); }
@Override public void setWritable(@NotNull VirtualFile file, boolean writableFlag) throws IOException { throw new IOException(VfsBundle.message("jar.modification.not.supported.error", file.getUrl())); }
@NotNull @Override public OutputStream getOutputStream(@NotNull VirtualFile file, Object requestor, long modStamp, long timeStamp) throws IOException { throw new IOException(VfsBundle.message("jar.modification.not.supported.error", file.getUrl())); }
@Override public InputStream getInputStream() throws IOException { throw new IOException(VfsBundle.message("file.read.error", getUrl())); }
@Override @NotNull public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException { throw new IOException(VfsBundle.message("file.write.error", getUrl())); }
@Override @NotNull public byte[] contentsToByteArray() throws IOException { throw new IOException(VfsBundle.message("file.read.error", getUrl())); }
private static void validateName(@NotNull String name) throws IOException { if (!isValidName(name)) { throw new IOException(VfsBundle.message("file.invalid.name.error", name)); } }
@NotNull @Override protected NotificationGroup compute() { return NotificationGroup.balloonGroup(VfsBundle.message("jar.copy.error.title")); }