Author: dbkr
Date: 2008-04-13 21:51:43 +0000 (Sun, 13 Apr 2008)
New Revision: 19273

Modified:
   trunk/apps/Freemail/src/freemail/AccountManager.java
Log:
Don't try & create accounts unless we actually want to. Don't fail to create an 
account because the directory already exists. Get username right for accounts.


Modified: trunk/apps/Freemail/src/freemail/AccountManager.java
===================================================================
--- trunk/apps/Freemail/src/freemail/AccountManager.java        2008-04-13 
21:39:22 UTC (rev 19272)
+++ trunk/apps/Freemail/src/freemail/AccountManager.java        2008-04-13 
21:51:43 UTC (rev 19273)
@@ -93,7 +93,10 @@
                                                +"\"), you may get problems 
accessing the account.");
                        }

-                       FreemailAccount account = new 
FreemailAccount(files[i].toString(), files[i], getAccountFile(files[i]));
+                       FreemailAccount account = new 
FreemailAccount(files[i].getName(), files[i], getAccountFile(files[i]));
+                       if (account == null) {
+                               Logger.error(this, "Couldn't initialise account 
from directory '"+files[i].getName()+"' - ignoring.");
+                       }

                        accounts.put(files[i].getName(), account);
                }
@@ -135,9 +138,9 @@
                }

                File accountdir = new File(datadir, username);
-               if (!accountdir.mkdir()) throw new IOException("Failed to 
create directory "+username+" in "+datadir);
+               if (!accountdir.exists() && !accountdir.mkdir()) throw new 
IOException("Failed to create directory "+username+" in "+datadir);

-               PropsFile accProps = getAccountFile(accountdir);
+               PropsFile accProps = newAccountFile(accountdir);

                FreemailAccount account = new FreemailAccount(username, 
accountdir, accProps);
                accounts.put(username, account);
@@ -182,6 +185,16 @@
        private static PropsFile getAccountFile(File accdir) {
                PropsFile accfile = new PropsFile(new File(accdir, 
ACCOUNT_FILE));

+               if (!accdir.exists() || !accfile.exists()) {
+                       return null;
+               }
+               
+               return accfile;
+       }
+       
+       private static PropsFile newAccountFile(File accdir) {
+               PropsFile accfile = new PropsFile(new File(accdir, 
ACCOUNT_FILE));
+               
                if (accdir.exists() && !accfile.exists()) {
                        initAccFile(accfile);
                }


Reply via email to