Use separate dirs for application logs, cache and configuration data

This is primarily used on Windows to store logs and cached data
on the local computers instead of on the network when roaming profiles
with folder redirection is used.
cusax-fix
Ingo Bauersachs 12 years ago
parent 6f79b98368
commit f2694065ad

@ -212,7 +212,7 @@ felix.auto.start.80= \
# file:lib/bundle/architectureviewer1.1.jar # file:lib/bundle/architectureviewer1.1.jar
# Specify the directory where oscar should deploy its bundles # Specify the directory where oscar should deploy its bundles
org.osgi.framework.storage=${net.java.sip.communicator.SC_HOME_DIR_LOCATION}/${net.java.sip.communicator.SC_HOME_DIR_NAME}/sip-communicator.bin org.osgi.framework.storage=${net.java.sip.communicator.SC_CACHE_DIR_LOCATION}/${net.java.sip.communicator.SC_HOME_DIR_NAME}/sip-communicator.bin
org.osgi.framework.startlevel.beginning=100 org.osgi.framework.startlevel.beginning=100
felix.startlevel.bundle=100 felix.startlevel.bundle=100

@ -295,7 +295,8 @@ void start(BundleContext bc, MetaContactListServiceImpl mclServImpl)
// get a reference to the contact list file. // get a reference to the contact list file.
try try
{ {
contactlistFile = faService.getPrivatePersistentFile(fileName); contactlistFile = faService.getPrivatePersistentFile(fileName,
FileCategory.PROFILE);
if (!contactlistFile.exists() && !contactlistFile.createNewFile()) if (!contactlistFile.exists() && !contactlistFile.createNewFile())
throw new IOException("Failed to create file" throw new IOException("Failed to create file"

@ -22,6 +22,7 @@
import javax.swing.text.html.HTML.*; import javax.swing.text.html.HTML.*;
import org.jitsi.service.configuration.*; import org.jitsi.service.configuration.*;
import org.jitsi.service.fileaccess.FileCategory;
import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.chat.history.*; import net.java.sip.communicator.impl.gui.main.chat.history.*;
@ -1841,7 +1842,7 @@ private static String getContactAvatar(
try try
{ {
avatarFile = GuiActivator.getFileAccessService() avatarFile = GuiActivator.getFileAccessService()
.getPrivatePersistentFile(avatarPath); .getPrivatePersistentFile(avatarPath, FileCategory.CACHE);
} }
catch (Exception e) catch (Exception e)
{ {
@ -1874,7 +1875,7 @@ private static String getContactAvatar(
try try
{ {
avatarFile = GuiActivator.getFileAccessService() avatarFile = GuiActivator.getFileAccessService()
.getPrivatePersistentFile(avatarPath); .getPrivatePersistentFile(avatarPath, FileCategory.CACHE);
} }
catch (Exception e) catch (Exception e)
{ {

@ -45,7 +45,7 @@ public static void deleteImage(int index)
{ {
File imageFile File imageFile
= GuiActivator.getFileAccessService().getPrivatePersistentFile( = GuiActivator.getFileAccessService().getPrivatePersistentFile(
fileName); fileName, FileCategory.CACHE);
if (imageFile.exists() && !imageFile.delete()) if (imageFile.exists() && !imageFile.delete())
logger.error("Failed to delete stored image at index " + index); logger.error("Failed to delete stored image at index " + index);
@ -72,7 +72,7 @@ public static BufferedImage loadImage(int index)
imageFile imageFile
= GuiActivator.getFileAccessService().getPrivatePersistentFile( = GuiActivator.getFileAccessService().getPrivatePersistentFile(
imagePath); imagePath, FileCategory.CACHE);
} }
catch (Exception e) catch (Exception e)
{ {
@ -108,11 +108,13 @@ private static void moveImage(int oldIndex, int newIndex)
try try
{ {
FileAccessService fas = GuiActivator.getFileAccessService(); FileAccessService fas = GuiActivator.getFileAccessService();
File oldFile = fas.getPrivatePersistentFile(oldImagePath); File oldFile = fas.getPrivatePersistentFile(oldImagePath,
FileCategory.CACHE);
if (oldFile.exists()) if (oldFile.exists())
{ {
File newFile = fas.getPrivatePersistentFile(newImagePath); File newFile = fas.getPrivatePersistentFile(newImagePath,
FileCategory.CACHE);
oldFile.renameTo(newFile); oldFile.renameTo(newFile);
} }
@ -147,12 +149,14 @@ public static void storeImage(BufferedImage image, int index)
try try
{ {
FileAccessService fas = GuiActivator.getFileAccessService(); FileAccessService fas = GuiActivator.getFileAccessService();
File storeDir = fas.getPrivatePersistentDirectory(STORE_DIR); File storeDir = fas.getPrivatePersistentDirectory(STORE_DIR,
FileCategory.CACHE);
// if dir doesn't exist create it // if dir doesn't exist create it
storeDir.mkdirs(); storeDir.mkdirs();
File file = fas.getPrivatePersistentFile(imagePath); File file = fas.getPrivatePersistentFile(imagePath,
FileCategory.CACHE);
ImageIO.write(image, "png", file); ImageIO.write(image, "png", file);
} }

@ -101,7 +101,7 @@ public Iterator<HistoryID> getExistingIDs()
= getFileAccessService().getPrivatePersistentDirectory( = getFileAccessService().getPrivatePersistentDirectory(
(userSetDataDirectory == null) (userSetDataDirectory == null)
? DATA_DIRECTORY ? DATA_DIRECTORY
: userSetDataDirectory); : userSetDataDirectory, FileCategory.PROFILE);
findDatFiles(vect, histDir); findDatFiles(vect, histDir);
} catch (Exception e) } catch (Exception e)
@ -246,24 +246,29 @@ private File createHistoryDirectories(HistoryID id)
throws IOException throws IOException
{ {
String[] idComponents = id.getID(); String[] idComponents = id.getID();
String[] dirs = new String[idComponents.length + 1];
String userSetDataDirectory = System.getProperty("HistoryServiceDirectory"); // escape chars in directory names
if(userSetDataDirectory != null)
dirs[0] = userSetDataDirectory;
else
dirs[0] = DATA_DIRECTORY;
// escape chars in direcotory names
escapeCharacters(idComponents); escapeCharacters(idComponents);
System.arraycopy(idComponents, 0, dirs, 1, dirs.length - 1); String userSetDataDirectory
= System.getProperty("HistoryServiceDirectory");
File dir = new File(userSetDataDirectory != null
? userSetDataDirectory
: DATA_DIRECTORY);
for (String s : idComponents)
{
dir = new File(dir, s);
}
File directory = null; File directory = null;
try try
{ {
directory directory
= getFileAccessService().getPrivatePersistentDirectory(dirs); = getFileAccessService().getPrivatePersistentDirectory(
dir.toString(),
FileCategory.PROFILE);
} }
catch (Exception e) catch (Exception e)
{ {
@ -475,7 +480,8 @@ private File getDirForHistory(HistoryID id)
= getFileAccessService().getPrivatePersistentDirectory( = getFileAccessService().getPrivatePersistentDirectory(
(userSetDataDirectory == null) (userSetDataDirectory == null)
? DATA_DIRECTORY ? DATA_DIRECTORY
: userSetDataDirectory); : userSetDataDirectory,
FileCategory.PROFILE);
} }
catch (Exception e) catch (Exception e)
{ {

@ -139,13 +139,15 @@ synchronized void start(BundleContext bc)
// Makes directory for custom bindings if it doesn't exist // Makes directory for custom bindings if it doesn't exist
File customDir = File customDir =
faService faService
.getPrivatePersistentDirectory(CUSTOM_KEYBINDING_DIR); .getPrivatePersistentDirectory(CUSTOM_KEYBINDING_DIR,
FileCategory.PROFILE);
if (!customDir.exists()) if (!customDir.exists())
customDir.mkdir(); customDir.mkdir();
// Gets file access service to reference persistent storage // Gets file access service to reference persistent storage
// of the user // of the user
customFile = faService.getPrivatePersistentFile(customPath); customFile = faService.getPrivatePersistentFile(customPath,
FileCategory.PROFILE);
} }
catch (Exception exc) catch (Exception exc)
{ {

@ -11,6 +11,7 @@
import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.*;
import org.jitsi.service.fileaccess.*;
import org.jitsi.service.packetlogging.*; import org.jitsi.service.packetlogging.*;
/** /**
@ -165,12 +166,11 @@ private void getFileNames()
for(int i = 0; i < fileCount; i++) for(int i = 0; i < fileCount; i++)
{ {
files[i] files[i]
= PacketLoggingActivator.getFileAccessService().getPrivatePersistentFile( = PacketLoggingActivator.getFileAccessService()
PacketLoggingActivator.LOGGING_DIR_NAME .getPrivatePersistentFile(
+ File.separator new File(PacketLoggingActivator.LOGGING_DIR_NAME,
+ "jitsi" "jitsi" + i + ".pcap").toString(),
+ i FileCategory.LOG);
+ ".pcap");
} }
} }

@ -11,6 +11,8 @@
import javax.imageio.*; import javax.imageio.*;
import org.jitsi.service.fileaccess.FileCategory;
import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.ServerStoredDetails.GenericDetail; import net.java.sip.communicator.service.protocol.ServerStoredDetails.GenericDetail;
import net.java.sip.communicator.service.protocol.ServerStoredDetails.ImageDetail; import net.java.sip.communicator.service.protocol.ServerStoredDetails.ImageDetail;
@ -397,13 +399,13 @@ private String storePicture(byte[] data)
+ msnProvider.getAccountID().getAccountUniqueID() + ".jpg"; + msnProvider.getAccountID().getAccountUniqueID() + ".jpg";
File storeDir = MsnActivator.getFileAccessService() File storeDir = MsnActivator.getFileAccessService()
.getPrivatePersistentDirectory(STORE_DIR); .getPrivatePersistentDirectory(STORE_DIR, FileCategory.CACHE);
// if dir doesn't exist create it // if dir doesn't exist create it
storeDir.mkdirs(); storeDir.mkdirs();
File file = MsnActivator.getFileAccessService() File file = MsnActivator.getFileAccessService()
.getPrivatePersistentFile(imagePath); .getPrivatePersistentFile(imagePath, FileCategory.CACHE);
ImageIO.write( ImageIO.write(
ImageIO.read(new ByteArrayInputStream(data)), ImageIO.read(new ByteArrayInputStream(data)),
@ -557,7 +559,7 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
+ msnProvider.getAccountID().getAccountUniqueID() + ".jpg"; + msnProvider.getAccountID().getAccountUniqueID() + ".jpg";
File file = MsnActivator.getFileAccessService() File file = MsnActivator.getFileAccessService()
.getPrivatePersistentFile(imagePath); .getPrivatePersistentFile(imagePath, FileCategory.CACHE);
if(file.exists()) if(file.exists())
{ {

@ -31,6 +31,20 @@ public class SIPCommunicator
private static final String[] LEGACY_DIR_NAMES private static final String[] LEGACY_DIR_NAMES
= { ".sip-communicator", "SIP Communicator" }; = { ".sip-communicator", "SIP Communicator" };
/**
* The name of the property that stores the home dir for cache data, such
* as avatars and spelling dictionaries.
*/
public static final String PNAME_SC_CACHE_DIR_LOCATION =
"net.java.sip.communicator.SC_CACHE_DIR_LOCATION";
/**
* The name of the property that stores the home dir for application log
* files (not history).
*/
public static final String PNAME_SC_LOG_DIR_LOCATION =
"net.java.sip.communicator.SC_LOG_DIR_LOCATION";
/** /**
* Name of the possible configuration file names (used under macosx). * Name of the possible configuration file names (used under macosx).
*/ */
@ -182,12 +196,14 @@ static void setScHomeDir(String osName)
* ${user.home}/.sip-communicator if it exists (and the new path isn't * ${user.home}/.sip-communicator if it exists (and the new path isn't
* already in use). * already in use).
*/ */
String location = System.getProperty(PNAME_SC_HOME_DIR_LOCATION); String profileLocation = System.getProperty(PNAME_SC_HOME_DIR_LOCATION);
String cacheLocation = System.getProperty(PNAME_SC_CACHE_DIR_LOCATION);
String logLocation = System.getProperty(PNAME_SC_LOG_DIR_LOCATION);
String name = System.getProperty(PNAME_SC_HOME_DIR_NAME); String name = System.getProperty(PNAME_SC_HOME_DIR_NAME);
boolean isHomeDirnameForced = name != null; boolean isHomeDirnameForced = name != null;
if ((location == null) || (name == null)) if (profileLocation == null || name == null)
{ {
String defaultLocation = System.getProperty("user.home"); String defaultLocation = System.getProperty("user.home");
String defaultName = ".jitsi"; String defaultName = ".jitsi";
@ -202,11 +218,22 @@ static void setScHomeDir(String osName)
if (osName.startsWith("Mac")) if (osName.startsWith("Mac"))
{ {
if (location == null) if (profileLocation == null)
location = profileLocation =
System.getProperty("user.home") + File.separator System.getProperty("user.home") + File.separator
+ "Library" + File.separator + "Library" + File.separator
+ "Application Support"; + "Application Support";
if (cacheLocation == null)
cacheLocation =
System.getProperty("user.home") + File.separator
+ "Library" + File.separator
+ "Caches";
if (logLocation == null)
logLocation =
System.getProperty("user.home") + File.separator
+ "Library" + File.separator
+ "Logs";
if (name == null) if (name == null)
name = "Jitsi"; name = "Jitsi";
} }
@ -218,15 +245,23 @@ else if (osName.startsWith("Windows"))
* it may be a good idea to follow the OS recommendations and * it may be a good idea to follow the OS recommendations and
* use APPDATA on pre-Vista systems as well. * use APPDATA on pre-Vista systems as well.
*/ */
if (location == null) if (profileLocation == null)
location = System.getenv("APPDATA"); profileLocation = System.getenv("APPDATA");
if (cacheLocation == null)
cacheLocation = System.getenv("LOCALAPPDATA");
if (logLocation == null)
logLocation = System.getenv("LOCALAPPDATA");
if (name == null) if (name == null)
name = "Jitsi"; name = "Jitsi";
} }
/* If there're no OS specifics, use the defaults. */ /* If there're no OS specifics, use the defaults. */
if (location == null) if (profileLocation == null)
location = defaultLocation; profileLocation = defaultLocation;
if (cacheLocation == null)
cacheLocation = profileLocation;
if (logLocation == null)
logLocation = profileLocation;
if (name == null) if (name == null)
name = defaultName; name = defaultName;
@ -236,23 +271,23 @@ else if (osName.startsWith("Windows"))
* doesn't look for the default dir. * doesn't look for the default dir.
*/ */
if (!isHomeDirnameForced if (!isHomeDirnameForced
&& (new File(location, name).isDirectory() == false) && (new File(profileLocation, name).isDirectory() == false)
&& new File(defaultLocation, defaultName).isDirectory()) && new File(defaultLocation, defaultName).isDirectory())
{ {
location = defaultLocation; profileLocation = defaultLocation;
name = defaultName; name = defaultName;
} }
// if we need to check legacy names and there is no current home dir // if we need to check legacy names and there is no current home dir
// already created // already created
if(chekLegacyDirNames if(chekLegacyDirNames
&& !checkHomeFolderExist(location, name, osName)) && !checkHomeFolderExist(profileLocation, name, osName))
{ {
// now check whether a legacy dir name exists and use it // now check whether a legacy dir name exists and use it
for(String dir : LEGACY_DIR_NAMES) for(String dir : LEGACY_DIR_NAMES)
{ {
// check the platform specific directory // check the platform specific directory
if(checkHomeFolderExist(location, dir, osName)) if(checkHomeFolderExist(profileLocation, dir, osName))
{ {
name = dir; name = dir;
break; break;
@ -262,18 +297,20 @@ && new File(defaultLocation, defaultName).isDirectory())
if(checkHomeFolderExist(defaultLocation, dir, osName)) if(checkHomeFolderExist(defaultLocation, dir, osName))
{ {
name = dir; name = dir;
location = defaultLocation; profileLocation = defaultLocation;
break; break;
} }
} }
} }
System.setProperty(PNAME_SC_HOME_DIR_LOCATION, location); System.setProperty(PNAME_SC_HOME_DIR_LOCATION, profileLocation);
System.setProperty(PNAME_SC_CACHE_DIR_LOCATION, cacheLocation);
System.setProperty(PNAME_SC_LOG_DIR_LOCATION, logLocation);
System.setProperty(PNAME_SC_HOME_DIR_NAME, name); System.setProperty(PNAME_SC_HOME_DIR_NAME, name);
} }
// when we end up with the home dirs, make sure we have log dir // when we end up with the home dirs, make sure we have log dir
new File(location, name + File.separator + "log").mkdirs(); new File(new File(logLocation, name), "log").mkdirs();
} }
/** /**

@ -20,6 +20,7 @@
import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.*;
import org.jitsi.service.configuration.*; import org.jitsi.service.configuration.*;
import org.jitsi.service.fileaccess.*;
import org.jitsi.service.resources.*; import org.jitsi.service.resources.*;
import org.osgi.framework.*; import org.osgi.framework.*;
@ -250,7 +251,8 @@ public void actionPerformed(ActionEvent e)
try try
{ {
f = DnsConfigActivator.getFileAccessService() f = DnsConfigActivator.getFileAccessService()
.getPrivatePersistentFile(".usednsjava"); .getPrivatePersistentFile(".usednsjava",
FileCategory.PROFILE);
if(chkEnabled.isSelected()) if(chkEnabled.isSelected())
{ {
if(!f.createNewFile() && !f.exists()) if(!f.createNewFile() && !f.exists())

@ -13,6 +13,7 @@
import net.java.sip.communicator.util.Logger; import net.java.sip.communicator.util.Logger;
import org.jitsi.service.fileaccess.*;
import org.jitsi.util.*; import org.jitsi.util.*;
/** /**
@ -124,7 +125,8 @@ private static void collectHomeFolderLogs(ZipOutputStream out)
try try
{ {
File[] fs = LoggingUtilsActivator.getFileAccessService() File[] fs = LoggingUtilsActivator.getFileAccessService()
.getPrivatePersistentDirectory(LOGGING_DIR_NAME).listFiles(); .getPrivatePersistentDirectory(LOGGING_DIR_NAME,
FileCategory.LOG).listFiles();
for(File f : fs) for(File f : fs)
{ {

@ -98,7 +98,8 @@ synchronized void start(BundleContext bc) throws Exception
SpellCheckActivator.getFileAccessService(); SpellCheckActivator.getFileAccessService();
// checks if DICT_DIR exists to see if this is the first run // checks if DICT_DIR exists to see if this is the first run
File dictionaryDir = faService.getPrivatePersistentFile(DICT_DIR); File dictionaryDir = faService.getPrivatePersistentFile(DICT_DIR,
FileCategory.CACHE);
if (!dictionaryDir.exists()) if (!dictionaryDir.exists())
{ {
@ -124,7 +125,8 @@ synchronized void start(BundleContext bc) throws Exception
String filename = dictUrl.getPath().substring(filenameStart); String filename = dictUrl.getPath().substring(filenameStart);
File dictLocation = File dictLocation =
faService.getPrivatePersistentFile(DICT_DIR + filename); faService.getPrivatePersistentFile(DICT_DIR + filename,
FileCategory.CACHE);
copyDictionary(source, dictLocation); copyDictionary(source, dictLocation);
} }
@ -133,7 +135,8 @@ synchronized void start(BundleContext bc) throws Exception
// gets resource for personal dictionary // gets resource for personal dictionary
this.personalDictLocation = this.personalDictLocation =
faService.getPrivatePersistentFile(DICT_DIR + PERSONAL_DICT_NAME); faService.getPrivatePersistentFile(DICT_DIR + PERSONAL_DICT_NAME,
FileCategory.PROFILE);
if (!personalDictLocation.exists()) if (!personalDictLocation.exists())
personalDictLocation.createNewFile(); personalDictLocation.createNewFile();
@ -379,7 +382,8 @@ void setLocale(Parameters.Locale locale) throws Exception
File dictLocation = File dictLocation =
SpellCheckActivator.getFileAccessService() SpellCheckActivator.getFileAccessService()
.getPrivatePersistentFile(DICT_DIR + filename); .getPrivatePersistentFile(DICT_DIR + filename,
FileCategory.CACHE);
// downloads dictionary if unavailable (not cached) // downloads dictionary if unavailable (not cached)
if (!dictLocation.exists()) if (!dictLocation.exists())
@ -430,7 +434,8 @@ void removeLocale(Parameters.Locale locale) throws Exception
File dictLocation = File dictLocation =
SpellCheckActivator.getFileAccessService() SpellCheckActivator.getFileAccessService()
.getPrivatePersistentFile(DICT_DIR + filename); .getPrivatePersistentFile(DICT_DIR + filename,
FileCategory.CACHE);
if (dictLocation.exists()) if (dictLocation.exists())
dictLocation.delete(); dictLocation.delete();
@ -457,7 +462,8 @@ boolean isLocaleAvailable(Parameters.Locale locale)
{ {
File dictLocation = File dictLocation =
SpellCheckActivator.getFileAccessService() SpellCheckActivator.getFileAccessService()
.getPrivatePersistentFile(DICT_DIR + filename); .getPrivatePersistentFile(DICT_DIR + filename,
FileCategory.CACHE);
return dictLocation.exists(); return dictLocation.exists();
} }

@ -176,7 +176,8 @@ private static byte[] getLocallyStoredAvatar(String avatarPath)
File avatarFile File avatarFile
= UtilActivator = UtilActivator
.getFileAccessService() .getFileAccessService()
.getPrivatePersistentFile(avatarPath); .getPrivatePersistentFile(avatarPath,
FileCategory.CACHE);
if(avatarFile.exists()) if(avatarFile.exists())
{ {
@ -297,10 +298,11 @@ private static void cacheAvatar(String avatarDirPath,
avatarDir avatarDir
= fileAccessService.getPrivatePersistentDirectory( = fileAccessService.getPrivatePersistentDirectory(
avatarDirPath); avatarDirPath, FileCategory.CACHE);
avatarFile avatarFile
= fileAccessService.getPrivatePersistentFile( = fileAccessService.getPrivatePersistentFile(
avatarDirPath + File.separator + avatarFileName); new File(avatarDirPath, avatarFileName).toString(),
FileCategory.CACHE);
if(!avatarFile.exists()) if(!avatarFile.exists())
{ {

@ -41,7 +41,7 @@ public class FileHandler
* %t, %h, %g, %u. * %t, %h, %g, %u.
* Also adds the special component : * Also adds the special component :
* %s sip-communicator's home directory, typically - * %s sip-communicator's home directory, typically -
* ${net.java.sip.communicator.SC_HOME_DIR_LOCATION}/ * ${net.java.sip.communicator.SC_LOG_DIR_LOCATION}/
* ${net.java.sip.communicator.SC_HOME_DIR_NAME}. * ${net.java.sip.communicator.SC_HOME_DIR_NAME}.
* <p> * <p>
* The field is public so that our <tt>Logger</tt> could reset it if * The field is public so that our <tt>Logger</tt> could reset it if
@ -135,9 +135,9 @@ private static String getPattern()
FileHandler.class.getName() + ".pattern"); FileHandler.class.getName() + ".pattern");
String homeLocation = System.getProperty( String homeLocation = System.getProperty(
"net.java.sip.communicator.SC_HOME_DIR_LOCATION"); "net.java.sip.communicator.SC_LOG_DIR_LOCATION");
String dirName = System.getProperty( String dirName = System.getProperty(
"net.java.sip.communicator.SC_HOME_DIR_NAME"); "net.java.sip.communicator.SC_HOME_DIR_NAME");
if(homeLocation != null && dirName != null) if(homeLocation != null && dirName != null)
{ {
@ -149,7 +149,7 @@ private static String getPattern()
homeLocation + "/" + dirName); homeLocation + "/" + dirName);
} }
// if pattern is missing and both dir name and home lcation // if pattern is missing and both dir name and home location
// properties are also not defined its most probably running from // properties are also not defined its most probably running from
// source or testing - lets create log directory in working dir. // source or testing - lets create log directory in working dir.
if(pattern == null) if(pattern == null)

@ -34,6 +34,20 @@ public class LaunchArgHandler
private static final String PNAME_SC_HOME_DIR_LOCATION = private static final String PNAME_SC_HOME_DIR_LOCATION =
"net.java.sip.communicator.SC_HOME_DIR_LOCATION"; "net.java.sip.communicator.SC_HOME_DIR_LOCATION";
/**
* The name of the property that stores the home dir for cache data, such
* as avatars or spelling dictionaries.
*/
private static final String PNAME_SC_CACHE_DIR_LOCATION =
"net.java.sip.communicator.SC_CACHE_DIR_LOCATION";
/**
* The name of the property that stores the home dir for application logs
* (not history).
*/
private static final String PNAME_SC_LOG_DIR_LOCATION =
"net.java.sip.communicator.SC_LOG_DIR_LOCATION";
/** /**
* The name of the property that contains the name of the SC configuration * The name of the property that contains the name of the SC configuration
* directory. * directory.
@ -381,6 +395,8 @@ private int handleConfigArg(String configArg)
} }
System.setProperty(PNAME_SC_HOME_DIR_LOCATION, configDir.getParent()); System.setProperty(PNAME_SC_HOME_DIR_LOCATION, configDir.getParent());
System.setProperty(PNAME_SC_CACHE_DIR_LOCATION, configDir.getParent());
System.setProperty(PNAME_SC_LOG_DIR_LOCATION, configDir.getParent());
System.setProperty(PNAME_SC_HOME_DIR_NAME, configDir.getName()); System.setProperty(PNAME_SC_HOME_DIR_NAME, configDir.getName());
//we instantiated our class logger before we had a chance to change //we instantiated our class logger before we had a chance to change

@ -473,17 +473,13 @@ private int writeLockFile(File lockFile, InetSocketAddress lockAddress)
*/ */
private File getLockFile() private File getLockFile()
{ {
String homeDirLocation String homeDirLocation =
= System.getProperty(SIPCommunicator.PNAME_SC_HOME_DIR_LOCATION); System
String homeDirName .getProperty(SIPCommunicator.PNAME_SC_CACHE_DIR_LOCATION);
= System.getProperty(SIPCommunicator.PNAME_SC_HOME_DIR_NAME); String homeDirName = System
String fileSeparator = System.getProperty("file.separator"); .getProperty(SIPCommunicator.PNAME_SC_HOME_DIR_NAME);
String fullLockFileName
= homeDirLocation + fileSeparator return new File(new File(homeDirLocation, homeDirName), LOCK_FILE_NAME);
+ homeDirName + fileSeparator
+ LOCK_FILE_NAME;
return new File(fullLockFileName);
} }
/** /**

@ -31,12 +31,6 @@ public class TestFileAccessService extends TestCase {
*/ */
private static final String dirName = "fileaccessservice.dir.tst"; private static final String dirName = "fileaccessservice.dir.tst";
/**
* The persistent directory's name.
*/
private static final String[] dirNames = { "fileaccessservice.dir.tst",
"subdir1", "subdir2" };
/** /**
* The persistent file's name. * The persistent file's name.
*/ */
@ -128,8 +122,8 @@ public void testCreateReadWriteFileInTemporaryDirectory()
public void testCreatePersistentDirectory() public void testCreatePersistentDirectory()
throws Exception { throws Exception {
try { try {
this.fileAccessService.getPrivatePersistentDirectory(dirName); this.fileAccessService.getPrivatePersistentDirectory(dirName,
this.fileAccessService.getPrivatePersistentDirectory(dirNames); FileCategory.PROFILE);
} catch (IOException e) } catch (IOException e)
{ {
fail("Error creating the temp directory: " + e.getMessage()); fail("Error creating the temp directory: " + e.getMessage());
@ -146,7 +140,8 @@ public void testCreateReadWriteFileInPersistentDirectory()
File privateDir = null; File privateDir = null;
try { try {
privateDir = this.fileAccessService privateDir = this.fileAccessService
.getPrivatePersistentDirectory(dirName); .getPrivatePersistentDirectory(dirName,
FileCategory.PROFILE);
} catch (IOException e) } catch (IOException e)
{ {
fail("Error creating the private directory: " + e.getMessage()); fail("Error creating the private directory: " + e.getMessage());
@ -178,7 +173,7 @@ public void testCreatePersistentFile()
{ {
try { try {
File file = this.fileAccessService File file = this.fileAccessService
.getPrivatePersistentFile(fileName); .getPrivatePersistentFile(fileName, FileCategory.PROFILE);
if (!file.exists()) if (!file.exists())
{ {
@ -201,7 +196,7 @@ public void testDeletePersistentFile()
{ {
try { try {
File file = this.fileAccessService File file = this.fileAccessService
.getPrivatePersistentFile(fileName); .getPrivatePersistentFile(fileName, FileCategory.PROFILE);
if (file.exists()) if (file.exists())
{ {
@ -221,7 +216,7 @@ public void testCreateReadWritePersistentFile()
try { try {
File file = this.fileAccessService File file = this.fileAccessService
.getPrivatePersistentFile(fileName); .getPrivatePersistentFile(fileName, FileCategory.PROFILE);
if (!file.exists()) if (!file.exists())
{ {
@ -243,7 +238,7 @@ public void testPersistentFilePersistency()
try { try {
File file = this.fileAccessService File file = this.fileAccessService
.getPrivatePersistentFile(fileName); .getPrivatePersistentFile(fileName, FileCategory.PROFILE);
if (!file.exists()) if (!file.exists())
{ {
@ -253,7 +248,7 @@ public void testPersistentFilePersistency()
writeReadFile(file); writeReadFile(file);
File newFile = this.fileAccessService File newFile = this.fileAccessService
.getPrivatePersistentFile(fileName); .getPrivatePersistentFile(fileName, FileCategory.PROFILE);
// Assert that those files are in fact the same // Assert that those files are in fact the same
assertEquals(file, newFile); assertEquals(file, newFile);

Loading…
Cancel
Save