Skip to content

Commit

Permalink
Merge pull request #418 from jburel/fix_posix_issue
Browse files Browse the repository at this point in the history
Fix posix issue
  • Loading branch information
jburel authored Dec 18, 2023
2 parents 4990bc1 + c5ec371 commit 4e8d075
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.File;
import java.text.SimpleDateFormat;
import java.nio.file.Files;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -62,8 +63,6 @@
import org.openmicroscopy.shoola.util.CommonsLangUtils;
import org.openmicroscopy.shoola.util.roi.io.ROIReader;

import com.google.common.io.Files;

import omero.gateway.model.DataObject;
import omero.gateway.model.ExperimenterData;
import omero.gateway.model.FileAnnotationData;
Expand Down Expand Up @@ -731,22 +730,23 @@ component, ctx, new FileAnnotationData(f),
*/
private File createFile(String imageName)
{
File dir = Files.createTempDir();
String name;
String fileName = null;
if (object != null) {
fileName = object.getTableName();
}
if (CommonsLangUtils.isBlank(fileName)) {
name = "ImageJ-"+FilenameUtils.getBaseName(
try {
final String prefix = "ome_";
File dir = Files.createTempDirectory(prefix).toFile();
String name;
String fileName = null;
if (object != null) {
fileName = object.getTableName();
}
if (CommonsLangUtils.isBlank(fileName)) {
name = "ImageJ-"+FilenameUtils.getBaseName(
FilenameUtils.removeExtension(imageName))+"-Results-";
name += new SimpleDateFormat("yyyy-MM-dd").format(new Date());
} else {
name = FilenameUtils.removeExtension(fileName);
}
name += new SimpleDateFormat("yyyy-MM-dd").format(new Date());
} else {
name = FilenameUtils.removeExtension(fileName);
}

name += ".csv";
try {
name += ".csv";
File f = new File(dir, name);
//read data
ROIReader reader = new ROIReader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import java.util.List;
import java.util.Map;

import com.google.common.io.Files;
import java.nio.file.Files;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
Expand Down Expand Up @@ -158,8 +160,8 @@ public void doCall() throws Exception

File tmpFolder = null;
try {
if(zip)
tmpFolder = Files.createTempDir();
if (zip)
tmpFolder = Files.createTempDirectory("ome_").toFile();
else
tmpFolder = folder;

Expand All @@ -173,7 +175,7 @@ public void doCall() throws Exception

result = new HashMap<Boolean, List<File>>();

if(CollectionUtils.isEmpty(files))
if (CollectionUtils.isEmpty(files))
return;

if (zip) {
Expand All @@ -185,7 +187,7 @@ public void doCall() throws Exception
File to = new File(f.getParentFile(), baseName
+ "."
+ FilenameUtils.getExtension(f.getName()));
Files.move(f, to);
Files.move(f.toPath(), to.toPath(), REPLACE_EXISTING);
f = copyFile(to, folder.getParentFile());
((Map<Boolean, List<File>>)result).put(Boolean.TRUE, Arrays.asList(f));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

import com.google.common.io.Files;
import java.nio.file.Files;

import org.openmicroscopy.shoola.env.LookupNames;
import org.openmicroscopy.shoola.env.data.OmeroMetadataService;
Expand Down Expand Up @@ -126,7 +126,7 @@ private void uploadFile(ImportErrorObject object)
}
}
if (b || id > 0) {
directory = Files.createTempDir();
directory = Files.createTempDirectory("ome_").toFile();
//Add the file to the directory.
if (f != null) {
directory = new File(directory.getParentFile(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import ij.ImagePlus;

import java.io.File;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
Expand All @@ -41,7 +42,7 @@
import org.openmicroscopy.shoola.util.CommonsLangUtils;
import org.openmicroscopy.shoola.util.roi.io.ROIReader;

import com.google.common.io.Files;


import omero.gateway.model.ExperimenterData;
import omero.gateway.model.FileAnnotationData;
Expand Down Expand Up @@ -83,17 +84,17 @@ public class ResultsSaver
*/
private File createFile(ImagePlus img, String fileName)
{
File dir = Files.createTempDir();
String name;
if (CommonsLangUtils.isBlank(fileName)) {
name = "ImageJ-"+FilenameUtils.getBaseName(
FilenameUtils.removeExtension(img.getTitle()))+"-Results-";
name += new SimpleDateFormat("yyyy-MM-dd").format(new Date());
} else {
name = FilenameUtils.removeExtension(fileName);
}
name += ".csv";
try {
File dir = Files.createTempDirectory("ome_").toFile();
String name;
if (CommonsLangUtils.isBlank(fileName)) {
name = "ImageJ-"+FilenameUtils.getBaseName(
FilenameUtils.removeExtension(img.getTitle()))+"-Results-";
name += new SimpleDateFormat("yyyy-MM-dd").format(new Date());
} else {
name = FilenameUtils.removeExtension(fileName);
}
name += ".csv";
File f = new File(dir, name);
//read data
ROIReader reader = new ROIReader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.FileOutputStream;
import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.zip.ZipEntry;
Expand All @@ -34,8 +35,6 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

import com.google.common.io.Files;

import junit.framework.TestCase;


Expand Down Expand Up @@ -136,11 +135,12 @@ private void clean(File f)
public void testZipDirectory()
{
try {
File dir = Files.createTempDir();
final String prefix = "test_ome";
File dir = Files.createTempDirectory(prefix).toFile();
File f = File.createTempFile("testZipDirectory", ".tmp", dir);
File zip = IOUtil.zipDirectory(dir);
assertEquals(FilenameUtils.getExtension(zip.getName()), "zip");
File destDir = Files.createTempDir();
File destDir = Files.createTempDirectory(prefix).toFile();
boolean b = unzip(zip, destDir);
assertEquals(true, b);
File[] files = destDir.listFiles();
Expand All @@ -159,15 +159,16 @@ public void testZipDirectory()
public void testZipDirectoryWithSubfolder()
{
try {
File dir = Files.createTempDir();
final String prefix = "test_ome";
File dir = Files.createTempDirectory(prefix).toFile();
File f = File.createTempFile("testZipDirectoryWithSubfolder", ".tmp", dir);
File subfolder = Files.createTempDir();
File subfolder = Files.createTempDirectory(prefix).toFile();
File f1 = File.createTempFile("sub_testZipDirectoryWithSubfolder", ".tmp", subfolder);

FileUtils.moveDirectoryToDirectory(subfolder, dir, false);

File zip = IOUtil.zipDirectory(dir);
File destDir = Files.createTempDir();
File destDir = Files.createTempDirectory(prefix).toFile();
boolean b = unzip(zip, destDir);
assertEquals(true, b);
File[] files = destDir.listFiles();
Expand Down

0 comments on commit 4e8d075

Please sign in to comment.