Bug 87327 - directory resource: dir not created automatically -> data lost
Summary: directory resource: dir not created automatically -> data lost
Status: RESOLVED FIXED
Alias: None
Product: korganizer
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR major
Target Milestone: ---
Assignee: Cornelius Schumacher
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-17 02:42 UTC by earlgrey
Modified: 2004-09-14 22:47 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description earlgrey 2004-08-17 02:42:30 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources

Add a calendar resource in local directory and typing the dir name.
The dir isn't created, but will allow you to save entries to the resource, on restart, then events have disappeared ( as no dir !)
Comment 1 Reinhold Kainhofer 2004-09-14 21:22:21 UTC
CVS commit by kainhofe: 

Backport of fixes for bugs 87327 (directory for local dir resource was never automatically created, and all data of that resource was just lost) and 87116 (read-only resources were also saved, causing error message boxes if the file wasn't writable).

CCMAIL: 87327@bugs.kde.org, 87116@bugs.kde.org


  M +11 -5     resourcecalendar.cpp   1.15.2.1
  M +31 -20    resourcelocaldir.cpp   1.21.2.1


--- kdepim/libkcal/resourcecalendar.cpp  #1.15:1.15.2.1
@@ -114,4 +114,5 @@ void ResourceCalendar::loadError( const 
 bool ResourceCalendar::save()
 {
+  if ( !readOnly() ) { 
   kdDebug(5800) << "Save resource " + resourceName() << endl;
 
@@ -122,4 +123,9 @@ bool ResourceCalendar::save()
 
   return success;
+  } else { 
+    // Read-only, just don't save... 
+    kdDebug(5800) << "Don't save read-only resource " + resourceName() << endl; 
+    return true; 
+  } 
 }
 

--- kdepim/libkcal/resourcelocaldir.cpp  #1.21:1.21.2.1
@@ -30,4 +30,5 @@
 #include <klocale.h>
 #include <kurl.h>
+#include <kstandarddirs.h>
 
 #include "vcaldrag.h"
@@ -126,6 +127,15 @@ bool ResourceLocalDir::doLoad()
 
   mCalendar.close();
+  bool success = true;
 
   QString dirName = mURL.path();
+  if ( !KStandardDirs::exists( dirName ) ) {
+    kdDebug(5800) << "ResourceLocalDir::load(): Directory doesn't exist yet. Creating it..." << endl;
+    
+    // Create the directory. Use 0775 to allow group-writable if the umask 
+    // allows it (permissions will be 0775 & ~umask). This is desired e.g. for
+    // group-shared directories!
+    success = KStandardDirs::makeDir( dirName, 0775 );
+  } else {
 
   kdDebug(5800) << "ResourceLocalDir::load(): '" << dirName << "'" << endl;
@@ -148,6 +158,7 @@ bool ResourceLocalDir::doLoad()
     if ( i ) mCalendar.addIncidence( i->clone() );
   }
+  }
 
-  return true;
+  return success;
 }
 


Comment 2 Reinhold Kainhofer 2004-09-14 22:47:33 UTC
CVS commit by kainhofe: 

Automatically create the directory for the local dir resource if it didn't exist yet. So far, the resource couldn't be saved since the dir didn't exist, but didn't even tell the user about it. 

CCMAIL: 87327-done@bugs.kde.org


  M +35 -45    resourcelocaldir.cpp   1.22
  M +0 -5      resourcelocaldir.h   1.14


--- kdepim/libkcal/resourcelocaldir.h  #1.13:1.14
@@ -73,7 +73,4 @@ class ResourceLocalDir : public Resource
 
   protected:
-    bool doOpen();
-    void doClose();
-
     bool doLoad();
     bool doSave();
@@ -86,6 +83,4 @@ class ResourceLocalDir : public Resource
     ICalFormat mFormat;
 
-    bool mOpen;
-
     KDirWatch mDirWatch;
     

--- kdepim/libkcal/resourcelocaldir.cpp  #1.21:1.22
@@ -30,4 +30,5 @@
 #include <klocale.h>
 #include <kurl.h>
+#include <kstandarddirs.h>
 
 #include "vcaldrag.h"
@@ -87,6 +88,4 @@ void ResourceLocalDir::init()
   setType( "dir" );
 
-  mOpen = false;
-
   connect( &mDirWatch, SIGNAL( dirty( const QString & ) ),
            SLOT( reload( const QString & ) ) );
@@ -110,25 +109,22 @@ ResourceLocalDir::~ResourceLocalDir()
 }
 
-bool ResourceLocalDir::doOpen()
-{
-  kdDebug(5800) << "Opening resource " << resourceName() << " with URL " << mURL.prettyURL() << endl;
-
-  mOpen = true;
-
-  return true;
-}
-
 bool ResourceLocalDir::doLoad()
 {
   kdDebug(5800) << "ResourceLocalDir::load()" << endl;
 
-  if ( !mOpen ) return true;
-
   mCalendar.close();
-
   QString dirName = mURL.path();
+  bool success = true;
 
-  kdDebug(5800) << "ResourceLocalDir::load(): '" << dirName << "'" << endl;
+  if ( !KStandardDirs::exists( dirName ) ) {
+    kdDebug(5800) << "ResourceLocalDir::load(): Directory doesn't exist yet. Creating it..." << endl;
+    
+    // Create the directory. Use 0775 to allow group-writable if the umask 
+    // allows it (permissions will be 0775 & ~umask). This is desired e.g. for
+    // group-shared directories!
+    success = KStandardDirs::makeDir( dirName, 0775 );
+  } else {
 
+    kdDebug(5800) << "ResourceLocalDir::load(): '" << dirName << "'" << endl;
   QDir dir( dirName );
 
@@ -143,11 +139,15 @@ bool ResourceLocalDir::doLoad()
     kdDebug(5800) << " read '" << fileName << "'" << endl;
     CalendarLocal cal( mCalendar.timeZoneId() );
-    cal.load( fileName );
+      success &= cal.load( fileName );
     Incidence::List incidences = cal.rawIncidences();
-    Incidence *i = incidences.first();
+      Incidence::List::ConstIterator it;
+      for ( it = incidences.constBegin(); it != incidences.constEnd(); ++it ) {
+        Incidence *i = *it;
     if ( i ) mCalendar.addIncidence( i->clone() );
   }
+    }
+  }
 
-  return true;
+  return success;
 }
 
@@ -156,6 +156,4 @@ bool ResourceLocalDir::doSave()
   kdDebug(5800) << "ResourceLocalDir::save()" << endl;
 
-  if ( !mOpen ) return true;
-
   Incidence::List incidences = mCalendar.rawIncidences();
 
@@ -183,5 +181,5 @@ void ResourceLocalDir::reload( const QSt
   kdDebug(5800) << "ResourceLocalDir::reload()" << endl;
 
-  if ( !mOpen ) return;
+  if ( !isOpen() ) return;
 
   kdDebug(5800) << "  File: '" << file << "'" << endl;
@@ -193,12 +191,4 @@ void ResourceLocalDir::reload( const QSt
 }
 
-void ResourceLocalDir::doClose()
-{
-  if ( !mOpen ) return;
-
-  mCalendar.close();
-  mOpen = false;
-}
-
 
 void ResourceLocalDir::deleteEvent(Event *event)