Skip to content

Commit

Permalink
MOD_SM_20150626 no tempdir if localsystem issue
Browse files Browse the repository at this point in the history
xutils enhancement port
  • Loading branch information
ogattaz committed Jun 26, 2015
1 parent 8b5c8d7 commit 954e030
Showing 1 changed file with 63 additions and 20 deletions.
83 changes: 63 additions & 20 deletions org.cohorte.utilities/src/org/psem2m/utilities/files/CXFileDir.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
*/
public class CXFileDir extends CXFileBase implements IXFilesContainer {

private static final CXFileDir DIR_TMP = new CXFileDir(
getTempAbsolutePath());
private static final long serialVersionUID = 3257562910606570550L;

private static final CXFileDir DIR_USER = new CXFileDir(
System.getProperty(CXJvmUtils.SYSPROP_USER_DIR));
private static final CXFileDir sTempDir = new CXFileDir(
getTempDirAbsolutePath());

private static final long serialVersionUID = 3257562910606570550L;
private static final CXFileDir sUserDir = new CXFileDir(
getUserDirAbsolutePath());

public static final boolean WITH_DIR = true;
public static final boolean WITH_TEXTFILE = true;
Expand Down Expand Up @@ -273,34 +273,77 @@ public static FileFilter getFilterSvn(final FileFilter aSubFileFilter) {
/**
* @return
*/
private static String getTempAbsolutePath() {
public static CXFileDir getTempDir() {

return sTempDir;
}

/**
* @return
*/
private static String getTempDirAbsolutePath() {

String wTempPath = System.getProperty("java.io.tmpdir");

// Windows 2008 - java.io.tmpdir could be empty
if (wTempPath == null || wTempPath.isEmpty()) {
wTempPath = System.getProperty("user.dir");
System.out
.println(String
.format("WARNING: The temporary folder \"java.io.tmpdir\" is not set. Uses \"user.dir\" as temp dir [%s]",
wTempPath));
System.setProperty("java.io.tmpdir", wTempPath);
}

String wPath = null;
try {
final File wTempFile = File.createTempFile("tmp", "txt");
wPath = wTempFile.getParent();
CXFileDir wTempDir = new CXFileDir(wTempPath);
if (!wTempDir.exists()) {
if (wTempDir.createHierarchy()) {
System.out.println(String
.format("WARNING: Creates temporary folder [%s]",
wTempPath));
}
}

} catch (Exception e1) {
Exception wEx = new Exception(String.format(
"Unable to create the temporary folder [%s]", wTempPath));
wEx.printStackTrace();
// default
return System.getProperty("user.dir");
}

try {
File wTempFile = File.createTempFile("tmp", "txt");
String wPath = wTempFile.getParent();
wTempFile.delete();
} catch (final Exception e) {
System.out.println(e.getMessage());
return wPath;
} catch (Exception e) {
Exception wEx = new Exception(
String.format(
"Unable to create a temporary file in the folder java.io.tmpdir=[%s] using the method File:createTempFile(...) ",
System.getProperty("java.io.tmpdir")), e);
wEx.printStackTrace();
// default
return System.getProperty("user.dir");
}
return wPath;
}

/**
*
* @return
*/
public static CXFileDir getTempDir() {
public static CXFileDir getUserDir() {

return DIR_TMP;
return sUserDir;
}

/**
*
* @return
*/
public static CXFileDir getUserDir() {

return DIR_USER;
private static String getUserDirAbsolutePath() {
return System.getProperty(CXJvmUtils.SYSPROP_USER_DIR);
}

/**
Expand Down Expand Up @@ -609,9 +652,9 @@ public ArrayList<File> getMyFiles(final FileFilter aFilter,

/*
* Renvoie la liste des Fichier et dossiers - Non recursif
*
*
* (non-Javadoc)
*
*
* @see
* org.psem2m.utilities.files.IXFilesContainer#getMyFiles(java.io.FileFilter
* , boolean, boolean)
Expand Down Expand Up @@ -1189,7 +1232,7 @@ public CXSortListFiles scanAllFiles(final boolean aWithSubDirs)
*/
/*
* (non-Javadoc)
*
*
* @see
* org.psem2m.utilities.files.IXFilesContainer#scanAllFiles(org.psem2m.utilities
* .files.CXSortListFiles, java.io.FileFilter, boolean, boolean)
Expand Down

0 comments on commit 954e030

Please sign in to comment.