# HG changeset patch # User Alexander Simon # Date 1328629081 -14400 # Node ID d6497ccca1a7ef3950c0d9099625b259fabe0e9a # Parent 5cb1e605f24751b8ceeb1f5eb3dae6759aed9da7 fixing Bug #207659 add temp file creation API to FileObject - second variant diff --git a/dlight.remote.impl/nbproject/project.xml b/dlight.remote.impl/nbproject/project.xml --- a/dlight.remote.impl/nbproject/project.xml +++ b/dlight.remote.impl/nbproject/project.xml @@ -85,7 +85,7 @@ - 7.56 + 7.59 diff --git a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileSystem.java b/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileSystem.java --- a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileSystem.java +++ b/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileSystem.java @@ -64,8 +64,11 @@ import javax.swing.SwingUtilities; import org.netbeans.modules.dlight.libs.common.PathUtilities; import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; +import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport; import org.netbeans.modules.nativeexecution.api.util.ConnectionListener; import org.netbeans.modules.nativeexecution.api.util.ConnectionManager; +import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException; +import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils; import org.netbeans.modules.remote.api.ui.ConnectionNotifier; import org.netbeans.modules.remote.spi.FileSystemCacheProvider; import org.netbeans.modules.remote.impl.RemoteLogger; @@ -261,6 +264,45 @@ return getRoot().getFileObject(name); } } + + @Override + public FileObject getTempFolder() throws IOException { + try { + String tmpName = HostInfoUtils.getHostInfo(execEnv).getTempDir(); + RemoteFileObjectBase tmpDir = findResource(tmpName); + if (tmpDir != null && tmpDir.isFolder() && tmpDir.isValid()) { + return tmpDir; + } + } catch (CancellationException ex) { + // + } + throw new IOException("Cannot find temporary folder"); // NOI18N + } + + @Override + public FileObject createTempFile(FileObject parent, String prefix, String suffix) throws IOException { + if (parent.isFolder() && parent.isValid()) { + while(true) { + File tmpFile = File.createTempFile(prefix, suffix); + String tmpName = tmpFile.getName(); + tmpFile.delete(); + try { + FileObject fo = parent.createData(tmpName); + if (fo != null && fo.isData() && fo.isValid()) { + return fo; + } + break; + } catch (IOException ex) { + FileObject test = parent.getFileObject(tmpName); + if (test != null) { + continue; + } + throw ex; + } + } + } + throw new IOException("Cannot create temporary file"); // NOI18N + } /*package*/ RemoteFileObjectBase findResource(String name, Set antiloop) { if (name.isEmpty() || name.equals("/")) { // NOI18N diff --git a/masterfs/nbproject/project.xml b/masterfs/nbproject/project.xml --- a/masterfs/nbproject/project.xml +++ b/masterfs/nbproject/project.xml @@ -63,7 +63,7 @@ - 7.54 + 7.59 diff --git a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystem.java b/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystem.java --- a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystem.java +++ b/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystem.java @@ -48,6 +48,7 @@ import java.io.IOException; import java.io.ObjectStreamException; import java.io.Serializable; +import java.security.SecureRandom; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -211,6 +212,28 @@ } return getFileObject(f); } + + @Override + public FileObject getTempFolder() throws IOException { + FileObject tmpDir = FileUtil.toFileObject(File.createTempFile("tmp", null).getParentFile()); // NOI18N + if (tmpDir != null && tmpDir.isFolder() && tmpDir.isValid()) { + return tmpDir; + } + throw new IOException("Cannot find temporary folder"); // NOI18N + } + + @Override + public FileObject createTempFile(FileObject parent, String prefix, String suffix) throws IOException { + if (parent.isFolder() && parent.isValid()) { + File tmpFile = File.createTempFile(prefix, suffix, FileUtil.toFile(parent)); + FileObject fo = FileUtil.toFileObject(tmpFile); + if (fo != null && fo.isData() && fo.isValid()) { + return fo; + } + tmpFile.delete(); + } + throw new IOException("Cannot create temporary file"); // NOI18N + } @Override public SystemAction[] getActions() { diff --git a/openide.filesystems/apichanges.xml b/openide.filesystems/apichanges.xml --- a/openide.filesystems/apichanges.xml +++ b/openide.filesystems/apichanges.xml @@ -49,6 +49,22 @@ Filesystems API + + + File System can create temporary file + + + + + +

+ Added methods to create temporary file objects: + FileSystem.getTempFolder, FileSystem.createTempFile. +

+
+ + +
Annotations to declare MIME type diff --git a/openide.filesystems/manifest.mf b/openide.filesystems/manifest.mf --- a/openide.filesystems/manifest.mf +++ b/openide.filesystems/manifest.mf @@ -2,5 +2,5 @@ OpenIDE-Module: org.openide.filesystems OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml -OpenIDE-Module-Specification-Version: 7.58 +OpenIDE-Module-Specification-Version: 7.59 diff --git a/openide.filesystems/src/org/openide/filesystems/FileSystem.java b/openide.filesystems/src/org/openide/filesystems/FileSystem.java --- a/openide.filesystems/src/org/openide/filesystems/FileSystem.java +++ b/openide.filesystems/src/org/openide/filesystems/FileSystem.java @@ -425,6 +425,26 @@ */ public abstract FileObject findResource(String name); + /** Returns temporary folder if it is avaliable on this file system. + * Method never returns null. IOException is thrown instead. + * @return a file object for temporary folder + */ + public FileObject getTempFolder() throws IOException { + throw new IOException("Unsupported operation"); // NOI18N + } + + /** Creates temporary file in the given parent folder. + * Method never returns null. IOException is thrown instead. + * @param parent the parent folder where temporary file will be created + * @param prefix prefix of the name of created file + * @param suffix suffix of the name of created file + * @return new temporary file + * @throws IOException + */ + public FileObject createTempFile(FileObject parent, String prefix, String suffix) throws IOException { + throw new IOException("Unsupported operation"); // NOI18N + } + /** Returns an array of actions that can be invoked on any file in * this filesystem. * These actions should preferably