[jitsi-dev] [libjitsi-commits] master: Add a classification for persistent files (dd4ca49)


#1

Hi Ingo,

I have some problems after that commit, when trying to change the home dir location.

If I uncomment the net.java.sip.communicator.SC_HOME_DIR_LOCATION property setup in the build.xml run target, I'm getting an ERROR :

ERROR: Unable to create cache directory: /schome/sip-communicator.bin

It tries to create the schome directory in the root directory, while it should create it in my home dir.

Could you please have a look?

Thanks!
Yana

···

On 11 Nov 2013, at 09:08, ingo@jitsi.org wrote:

Repository : ssh://lists.jitsi.org/libjitsi

On branch : master
Link : https://github.com/jitsi/libjitsi/compare/4d7f9a0e4990db83f70421cd1c5a55d3a39a1cba...dd4ca49543b1d560ca678b7e91ccf75ef7fe6d9a

---------------------------------------------------------------

commit dd4ca49543b1d560ca678b7e91ccf75ef7fe6d9a
Author: Ingo Bauersachs <ingo@jitsi.org>
Date: Tue Aug 6 17:25:06 2013 +0200

   Add a classification for persistent files

   This is primarily used by Jitsi 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.

---------------------------------------------------------------

dd4ca49543b1d560ca678b7e91ccf75ef7fe6d9a
.../impl/fileaccess/FileAccessServiceImpl.java | 202 ++++++++------------
src/org/jitsi/impl/neomedia/MediaServiceImpl.java | 2 +-
.../transform/zrtp/ZRTPTransformEngine.java | 4 +-
.../configuration/ConfigurationService.java | 19 +-
.../service/fileaccess/FileAccessService.java | 51 +++--
src/org/jitsi/service/fileaccess/FileCategory.java | 33 ++++
6 files changed, 159 insertions(+), 152 deletions(-)

diff --git a/src/org/jitsi/impl/fileaccess/FileAccessServiceImpl.java b/src/org/jitsi/impl/fileaccess/FileAccessServiceImpl.java
index c65792b..31b06d9 100644
--- a/src/org/jitsi/impl/fileaccess/FileAccessServiceImpl.java
+++ b/src/org/jitsi/impl/fileaccess/FileAccessServiceImpl.java
@@ -22,7 +22,6 @@ import org.jitsi.util.*;
*/
public class FileAccessServiceImpl implements FileAccessService
{
-
    /**
     * The <tt>Logger</tt> used by the <tt>FileAccessServiceImpl</tt> class and
     * its instances for logging output.
@@ -40,19 +39,32 @@ public class FileAccessServiceImpl implements FileAccessService
     */
    public static final String TEMP_FILE_SUFFIX = "TEMP";

- private final String scHomeDirLocation;
-
+ private final String profileDirLocation;
+ private final String cacheDirLocation;
+ private final String logDirLocation;
    private final String scHomeDirName;

    public FileAccessServiceImpl()
    {
- scHomeDirLocation
+ profileDirLocation
            = getSystemProperty(
                    ConfigurationService.PNAME_SC_HOME_DIR_LOCATION);
- if (scHomeDirLocation == null)
+ if (profileDirLocation == null)
            throw new IllegalStateException(
                    ConfigurationService.PNAME_SC_HOME_DIR_LOCATION);

+ String cacheDir
+ = getSystemProperty(
+ ConfigurationService.PNAME_SC_CACHE_DIR_LOCATION);
+ cacheDirLocation =
+ (cacheDir == null) ? profileDirLocation : cacheDir;
+
+ String logDir
+ = getSystemProperty(
+ ConfigurationService.PNAME_SC_LOG_DIR_LOCATION);
+ logDirLocation =
+ (logDir == null) ? profileDirLocation : logDir;
+
        scHomeDirName
            = getSystemProperty(ConfigurationService.PNAME_SC_HOME_DIR_NAME);
        if (scHomeDirName == null)
@@ -115,39 +127,47 @@ public class FileAccessServiceImpl implements FileAccessService
    }

    /**
+ * Please use {@link #getPrivatePersistentFile(String, FileCategory)}.
+ */
+ @Deprecated
+ public File getPrivatePersistentFile(String fileName)
+ throws Exception
+ {
+ return this.getPrivatePersistentFile(fileName, FileCategory.PROFILE);
+ }
+
+ /**
     * This method returns a file specific to the current user. It may not
     * exist, but it is guaranteed that you will have the sufficient rights to
     * create it.
     *
     * This file should not be considered secure because the implementor may
- * return a file accesible to everyone. Generaly it will reside in current
+ * return a file accessible to everyone. Generally it will reside in current
     * user's homedir, but it may as well reside in a shared directory.
     *
     * Note: DO NOT store unencrypted sensitive information in this file
     *
     * @param fileName
     * The name of the private file you wish to access
+ * @param category
+ * The classification of the file.
     * @return The file
     * @throws Exception if we faile to create the file.
     */
- public File getPrivatePersistentFile(String fileName)
+ public File getPrivatePersistentFile(String fileName, FileCategory category)
        throws Exception
    {
+ logger.logEntry();

        File file = null;
-
        try
        {
- logger.logEntry();
-
- String fullPath = getFullPath(fileName);
- file = accessibleFile(fullPath, fileName);
-
+ file = accessibleFile(getFullPath(category), fileName);
            if (file == null)
            {
                throw new SecurityException("Insufficient rights to access "
                    + "this file in current user's home directory: "
- + new File(fullPath, fileName).getPath());
+ + new File(getFullPath(category), fileName).getPath());
            }
        }
        finally
@@ -159,11 +179,22 @@ public class FileAccessServiceImpl implements FileAccessService
    }

    /**
+ * Please use {@link #getPrivatePersistentDirectory(String, FileCategory)}
+ */
+ @Deprecated
+ public File getPrivatePersistentDirectory(String dirName)
+ throws Exception
+ {
+ return getPrivatePersistentDirectory(dirName, FileCategory.PROFILE);
+ }
+
+ /**
     * This method creates a directory specific to the current user.
     *
     * This directory should not be considered secure because the implementor
- * may return a directory accesible to everyone. Generaly it will reside in
- * current user's homedir, but it may as well reside in a shared directory.
+ * may return a directory accessible to everyone. Generally it will reside
+ * in current user's homedir, but it may as well reside in a shared
+ * directory.
     *
     * It is guaranteed that you will be able to create files in it.
     *
@@ -171,17 +202,17 @@ public class FileAccessServiceImpl implements FileAccessService
     *
     * @param dirName
     * The name of the private directory you wish to access.
+ * @param category
+ * The classification of the directory.
     * @return The created directory.
     * @throws Exception
     * Thrown if there is no suitable location for the persistent
     * directory.
     */
- public File getPrivatePersistentDirectory(String dirName)
- throws Exception
+ public File getPrivatePersistentDirectory(String dirName,
+ FileCategory category) throws Exception
    {
- String fullPath = getFullPath(dirName);
- File dir = new File(fullPath, dirName);
-
+ File dir = new File(getFullPath(category), dirName);
        if (dir.exists())
        {
            if (!dir.isDirectory())
@@ -203,93 +234,29 @@ public class FileAccessServiceImpl implements FileAccessService
    }

    /**
- * This method creates a directory specific to the current user.
- *
- * {@link #getPrivatePersistentDirectory(String)}
- *
- * @param dirNames
- * The name of the private directory you wish to access.
- * @return The created directory.
- * @throws Exception
- * Thrown if there is no suitable location for the persistent
- * directory.
- */
- public File getPrivatePersistentDirectory(String[] dirNames)
- throws Exception
- {
- StringBuilder dirName = new StringBuilder();
- for (int i = 0; i < dirNames.length; i++)
- {
- if (i > 0)
- {
- dirName.append(File.separatorChar);
- }
- dirName.append(dirNames[i]);
- }
-
- return getPrivatePersistentDirectory(dirName.toString());
- }
-
- /**
- * Returns the full parth corresponding to a file located in the
+ * Returns the full path corresponding to a file located in the
     * sip-communicator config home and carrying the specified name.
- * @param fileName the name of the file whose location we're looking for.
- * @return the config home location of a a file withe the specified name.
+ * @param category The classification of the file or directory.
+ * @return the config home location of a a file with the specified name.
     */
- private String getFullPath(String fileName)
+ private File getFullPath(FileCategory category)
    {
        // bypass the configurationService here to remove the dependency
- String userhome = getScHomeDirLocation();
- String sipSubdir = getScHomeDirName();
-
- if (!userhome.endsWith(File.separator))
+ String directory;
+ switch (category)
        {
- userhome += File.separator;
+ case CACHE:
+ directory = this.cacheDirLocation;
+ break;
+ case LOG:
+ directory = this.logDirLocation;
+ break;
+ default:
+ directory = this.profileDirLocation;
+ break;
        }
- if (!sipSubdir.endsWith(File.separator))
- {
- sipSubdir += File.separator;
- }
-
- return userhome + sipSubdir;
- }
-
- /**
- * Returns the name of the directory where SIP Communicator is to store user
- * specific data such as configuration files, message and call history
- * as well as is bundle repository.
- *
- * @return the name of the directory where SIP Communicator is to store
- * user specific data such as configuration files, message and call history
- * as well as is bundle repository.
- */
- private String getScHomeDirName()
- {
- String scHomeDirName = this.scHomeDirName;

- if (scHomeDirName == null)
- scHomeDirName = ".sip-communicator";
-
- return scHomeDirName;
- }
-
- /**
- * Returns the location of the directory where SIP Communicator is to store
- * user specific data such as configuration files, message and call history
- * as well as is bundle repository.
- *
- * @return the location of the directory where SIP Communicator is to store
- * user specific data such as configuration files, message and call history
- * as well as is bundle repository.
- */
- private String getScHomeDirLocation()
- {
- String scHomeDirLocation = this.scHomeDirLocation;
-
- if (scHomeDirLocation == null)
- scHomeDirLocation = getSystemProperty("user.home");
-
- return scHomeDirLocation;
+ return new File(directory, this.scHomeDirName);
    }

    /**
@@ -314,6 +281,7 @@ public class FileAccessServiceImpl implements FileAccessService
        }
        return retval;
    }
+
    /**
     * Checks if a file exists and if it is writable or readable. If not -
     * checks if the user has a write privileges to the containing directory.
@@ -328,7 +296,7 @@ public class FileAccessServiceImpl implements FileAccessService
     * @throws IOException
     * Thrown if the home directory cannot be created
     */
- private static File accessibleFile(String homedir, String fileName)
+ private static File accessibleFile(File homedir, String fileName)
            throws IOException
    {
        File file = null;
@@ -337,29 +305,21 @@ public class FileAccessServiceImpl implements FileAccessService
        {
            logger.logEntry();

- homedir = homedir.trim();
- if (!homedir.endsWith(File.separator))
- {
- homedir += File.separator;
- }
-
- file = new File(homedir + fileName);
+ file = new File(homedir, fileName);
            if (file.canRead() || file.canWrite())
            {
                return file;
            }

- File homedirFile = new File(homedir);
-
- if (!homedirFile.exists())
+ if (!homedir.exists())
            {
                if (logger.isDebugEnabled())
                    logger.debug("Creating home directory : "
- + homedirFile.getAbsolutePath());
- if (!homedirFile.mkdirs())
+ + homedir.getAbsolutePath());
+ if (!homedir.mkdirs())
                {
                    String message = "Could not create the home directory : "
- + homedirFile.getAbsolutePath();
+ + homedir.getAbsolutePath();

                    if (logger.isDebugEnabled())
                        logger.debug(message);
@@ -367,9 +327,9 @@ public class FileAccessServiceImpl implements FileAccessService
                }
                if (logger.isDebugEnabled())
                    logger.debug("Home directory created : "
- + homedirFile.getAbsolutePath());
+ + homedir.getAbsolutePath());
            }
- else if (!homedirFile.canWrite())
+ else if (!homedir.canWrite())
            {
                file = null;
            }
@@ -379,15 +339,15 @@ public class FileAccessServiceImpl implements FileAccessService
                if (!file.getParentFile().mkdirs())
                {
                    String message = "Could not create the parent directory : "
- + homedirFile.getAbsolutePath();
+ + homedir.getAbsolutePath();

- if (logger.isDebugEnabled())
- logger.debug(message);
+ logger.debug(message);
                    throw new IOException(message);
                }
            }

- } finally
+ }
+ finally
        {
            logger.logExit();
        }
diff --git a/src/org/jitsi/impl/neomedia/MediaServiceImpl.java b/src/org/jitsi/impl/neomedia/MediaServiceImpl.java
index 0e2d714..22f35ad 100755
--- a/src/org/jitsi/impl/neomedia/MediaServiceImpl.java
+++ b/src/org/jitsi/impl/neomedia/MediaServiceImpl.java
@@ -1529,7 +1529,7 @@ public class MediaServiceImpl

        String scHomeDirLocation
            = System.getProperty(
- ConfigurationService.PNAME_SC_HOME_DIR_LOCATION);
+ ConfigurationService.PNAME_SC_CACHE_DIR_LOCATION);

        if (scHomeDirLocation != null)
        {
diff --git a/src/org/jitsi/impl/neomedia/transform/zrtp/ZRTPTransformEngine.java b/src/org/jitsi/impl/neomedia/transform/zrtp/ZRTPTransformEngine.java
index 9d1678f..a37f8a6 100644
--- a/src/org/jitsi/impl/neomedia/transform/zrtp/ZRTPTransformEngine.java
+++ b/src/org/jitsi/impl/neomedia/transform/zrtp/ZRTPTransformEngine.java
@@ -500,7 +500,9 @@ public class ZRTPTransformEngine
            try
            {
                // Create the zid file
- file = faService.getPrivatePersistentFile(zidFilename);
+ file =
+ faService.getPrivatePersistentFile(zidFilename,
+ FileCategory.PROFILE);
            }
            catch (Exception e)
            {
diff --git a/src/org/jitsi/service/configuration/ConfigurationService.java b/src/org/jitsi/service/configuration/ConfigurationService.java
index fd42d8f..f5f93e1 100644
--- a/src/org/jitsi/service/configuration/ConfigurationService.java
+++ b/src/org/jitsi/service/configuration/ConfigurationService.java
@@ -23,7 +23,7 @@ public interface ConfigurationService
    /**
     * The name of the property that indicates the name of the directory where
     * Jitsi is to store user specific data such as configuration
- * files, message and call history as well as is bundle repository.
+ * files, message and call history.
     */
    public static final String PNAME_SC_HOME_DIR_NAME
        = "net.java.sip.communicator.SC_HOME_DIR_NAME";
@@ -31,13 +31,26 @@ public interface ConfigurationService
    /**
     * The name of the property that indicates the location of the directory
     * where Jitsi is to store user specific data such as
- * configuration files, message and call history as well as is bundle
- * repository.
+ * configuration files, message and call history.
     */
    public static final String PNAME_SC_HOME_DIR_LOCATION
        = "net.java.sip.communicator.SC_HOME_DIR_LOCATION";

    /**
+ * The name of the property that indicates the location of the directory
+ * where Jitsi is to store cached data.
+ */
+ public static final String PNAME_SC_CACHE_DIR_LOCATION
+ = "net.java.sip.communicator.SC_CACHE_DIR_LOCATION";
+
+ /**
+ * The name of the property that indicates the location of the directory
+ * where Jitsi is to store cached data.
+ */
+ public static final String PNAME_SC_LOG_DIR_LOCATION
+ = "net.java.sip.communicator.SC_LOG_DIR_LOCATION";
+
+ /**
     * The name of the boolean system property which indicates whether the
     * configuration file is to be considered read-only. The default value is
     * <tt>false</tt> which means that the configuration file is considered
diff --git a/src/org/jitsi/service/fileaccess/FileAccessService.java b/src/org/jitsi/service/fileaccess/FileAccessService.java
index da98f16..3899cb9 100644
--- a/src/org/jitsi/service/fileaccess/FileAccessService.java
+++ b/src/org/jitsi/service/fileaccess/FileAccessService.java
@@ -17,15 +17,8 @@ import java.io.*;
*
* @author Alexander Pelov
*/
-public interface FileAccessService {
-
- /**
- * The key of the configuration property containing the user home dir - if
- * it is not defined the system property is used
- */
- public static final String CONFPROPERTYKEY_USER_HOME
- = "net.java.sip.communicator.fileaccess.USER_HOME";
-
+public interface FileAccessService
+{
    /**
     * This method returns a created temporary file. After you close this file
     * it is not guaranteed that you will be able to open it again nor that it
@@ -54,24 +47,41 @@ public interface FileAccessService {
    File getTemporaryDirectory() throws IOException;

    /**
+ * Please use {@link #getPrivatePersistentFile(String, FileCategory)}.
+ */
+ @Deprecated
+ File getPrivatePersistentFile(String fileName)
+ throws Exception;
+
+ /**
     * This method returns a file specific to the current user. It may not
     * exist, but it is guaranteed that you will have the sufficient rights to
     * create it.
     *
     * This file should not be considered secure because the implementor may
- * return a file accesible to everyone. Generaly it will reside in current
+ * return a file accessible to everyone. Generally it will reside in current
     * user's homedir, but it may as well reside in a shared directory.
     *
     * Note: DO NOT store unencrypted sensitive information in this file
     *
     * @param fileName
     * The name of the private file you wish to access
+ * @param category
+ * The classification of the file.
     * @return The file
     * @throws Exception
     * Thrown if there is no suitable location for the persistent
     * file
     */
- File getPrivatePersistentFile(String fileName) throws Exception;
+ File getPrivatePersistentFile(String fileName, FileCategory category)
+ throws Exception;
+
+ /**
+ * Please use {@link #getPrivatePersistentDirectory(String, FileCategory)}
+ */
+ @Deprecated
+ File getPrivatePersistentDirectory(String dirName)
+ throws Exception;

    /**
     * This method creates a directory specific to the current user.
@@ -87,26 +97,15 @@ public interface FileAccessService {
     *
     * @param dirName
     * The name of the private directory you wish to access.
+ * @param category
+ * The classification of the directory.
     * @return The created directory.
     * @throws Exception
     * Thrown if there is no suitable location for the persistent
     * directory.
     */
- File getPrivatePersistentDirectory(String dirName) throws Exception;
-
- /**
- * This method creates a directory specific to the current user.
- *
- * {@link #getPrivatePersistentDirectory(String)}
- *
- * @param dirNames
- * The name of the private directory you wish to access.
- * @return The created directory.
- * @throws Exception
- * Thrown if there is no suitable location for the persistent
- * directory.
- */
- File getPrivatePersistentDirectory(String[] dirNames) throws Exception;
+ File getPrivatePersistentDirectory(String dirName, FileCategory category)
+ throws Exception;

    /**
     * Returns the default download directory depending on the operating system.
diff --git a/src/org/jitsi/service/fileaccess/FileCategory.java b/src/org/jitsi/service/fileaccess/FileCategory.java
new file mode 100644
index 0000000..b1a6af7
--- /dev/null
+++ b/src/org/jitsi/service/fileaccess/FileCategory.java
@@ -0,0 +1,33 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license. See terms of license at gnu.org.
+ */
+package org.jitsi.service.fileaccess;
+
+/**
+ * High-level classification for files or directories created by Jitsi.
+ *
+ * @author Ingo Bauersachs
+ */
+public enum FileCategory
+{
+ /**
+ * For files or directories that contain configuration data or similar data
+ * that belongs to a specific user, but might non-simultaneously be shared
+ * across different computers or operating systems.
+ */
+ PROFILE,
+
+ /**
+ * For files or directories that contain cached data. It must be safe to
+ * delete these files at any time.
+ */
+ CACHE,
+
+ /**
+ * For files or directories that contain log data that is bound to a
+ * specific user and computer. This is NOT for history related data.
+ */
+ LOG
+}

_______________________________________________
commits mailing list
commits@jitsi.org
Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/commits


#2

Hey

I have some problems after that commit, when trying to change the home
dir location.

If I uncomment the net.java.sip.communicator.SC_HOME_DIR_LOCATION property
setup in the build.xml run target, I'm getting an ERROR :

What do you set as the value for this property?

ERROR: Unable to create cache directory: /schome/sip-communicator.bin

It tries to create the schome directory in the root directory, while it
should create it in my home dir.

Could you please have a look?

Thanks!
Yana

Ingo


#3

Hey,

Hey

I have some problems after that commit, when trying to change the home
dir location.

If I uncomment the net.java.sip.communicator.SC_HOME_DIR_LOCATION property
setup in the build.xml run target, I'm getting an ERROR :

What do you set as the value for this property?

I just uncommented what is already in the build.xml "run" target and the value is "schome". This has been there for a long time and I've used it as is.

Yana

···

On 11 Nov 2013, at 17:34, Ingo Bauersachs <ingo@jitsi.org> wrote:

ERROR: Unable to create cache directory: /schome/sip-communicator.bin

It tries to create the schome directory in the root directory, while it
should create it in my home dir.

Could you please have a look?

Thanks!
Yana

Ingo

_______________________________________________
dev mailing list
dev@jitsi.org
Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/dev


#4

I have some problems after that commit, when trying to change the home
dir location.

If I uncomment the net.java.sip.communicator.SC_HOME_DIR_LOCATION

property

setup in the build.xml run target, I'm getting an ERROR :

What do you set as the value for this property?

I just uncommented what is already in the build.xml "run" target and the
value is "schome". This has been there for a long time and I've used it
as is.

Yana

ERROR: Unable to create cache directory: /schome/sip-communicator.bin

It tries to create the schome directory in the root directory, while it
should create it in my home dir.

Could you please have a look?

Commit 8ad5e173d8ef296c3aa72ddc2214a2d93552b024 should fix this. Thanks for
noticing!

Thanks!
Yana

Ingo

Ingo


#5

Hi Ingo,

I have some problems after that commit, when trying to change the home
dir location.

If I uncomment the net.java.sip.communicator.SC_HOME_DIR_LOCATION

property

setup in the build.xml run target, I'm getting an ERROR :

What do you set as the value for this property?

I just uncommented what is already in the build.xml "run" target and the
value is "schome". This has been there for a long time and I've used it
as is.

Yana

ERROR: Unable to create cache directory: /schome/sip-communicator.bin

It tries to create the schome directory in the root directory, while it
should create it in my home dir.

Could you please have a look?

Commit 8ad5e173d8ef296c3aa72ddc2214a2d93552b024 should fix this. Thanks for
noticing!

Great! Thanks for the quick fix!

Yana

···

On 11 Nov 2013, at 19:37, Ingo Bauersachs <ingo@jitsi.org> wrote:

Thanks!
Yana

Ingo

Ingo

_______________________________________________
dev mailing list
dev@jitsi.org
Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/dev