[haiku-commits] haiku: hrev45005 - src/apps/mail

  • From: stpere@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 13 Dec 2012 03:51:27 +0100 (CET)

hrev45005 adds 1 changeset to branch 'master'
old head: 55ef15c45a831152b1544a28c34de4aa71e151ff
new head: 53b234eb1c4b0d191c9d8c84d7801b63776f9939
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=53b234e+%5E55ef15c

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

53b234e: Mail: Reworking of the unique filename discovery (drafts)

                                [ Philippe Saint-Pierre <stpere@xxxxxxxxx> ]

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

Revision:    hrev45005
Commit:      53b234eb1c4b0d191c9d8c84d7801b63776f9939
URL:         http://cgit.haiku-os.org/haiku/commit/?id=53b234e
Author:      Philippe Saint-Pierre <stpere@xxxxxxxxx>
Date:        Thu Dec 13 02:49:20 2012 UTC

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

1 file changed, 15 insertions(+), 8 deletions(-)
src/apps/mail/MailWindow.cpp | 23 +++++++++++++++--------

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

diff --git a/src/apps/mail/MailWindow.cpp b/src/apps/mail/MailWindow.cpp
index 1c246e8..5b0c6bc 100644
--- a/src/apps/mail/MailWindow.cpp
+++ b/src/apps/mail/MailWindow.cpp
@@ -2548,11 +2548,11 @@ TMailWindow::SaveAsDraft()
                                        return status;
                        case B_OK:
                        {
-                               char fileName[B_FILE_NAME_LENGTH], *eofn;
+                               char fileName[B_FILE_NAME_LENGTH];
                                // save as some version of the message's subject
                                strlcpy(fileName, fHeaderView->fSubject->Text(),
                                        sizeof(fileName));
-                               eofn = fileName + strlen(fileName);
+                               uint32 originalLength = strlen(fileName);
 
                                // convert /, \ and : to -
                                for (char *bad = fileName; (bad = strchr(bad, 
'/')) != NULL;
@@ -2564,12 +2564,19 @@ TMailWindow::SaveAsDraft()
 
                                // Create the file; if the name exists, find a 
unique name
                                flags = B_WRITE_ONLY | B_CREATE_FILE | 
B_FAIL_IF_EXISTS;
-                               for (int32 i = 1; (status = draft.SetTo(&dir, 
fileName, flags))
-                                       != B_OK; i++) {
-                                       if (status != B_FILE_EXISTS)
-                                               return status;
-                                       sprintf(eofn, "%ld", i);
-                               }
+                               int32 i = 1;
+                               do {
+                                       status = draft.SetTo(&dir, fileName, 
flags);
+                                       if (status == B_OK)
+                                               break;
+                                       char appendix[B_FILE_NAME_LENGTH];
+                                       sprintf(appendix, " %ld", i++);
+                                       int32 pos = min_c(sizeof(fileName) - 
strlen(appendix), 
+                                               originalLength);
+                                       sprintf(fileName + pos, "%s", appendix);
+                               } while (status == B_FILE_EXISTS);
+                               if (status != B_OK)
+                                       return status;
 
                                // Cache the ref
                                if (fRef == NULL)


Other related posts:

  • » [haiku-commits] haiku: hrev45005 - src/apps/mail - stpere