Bug 157100 - handle file write errors
Summary: handle file write errors
Status: RESOLVED FIXED
Alias: None
Product: kphotoalbum
Classification: Applications
Component: general (show other bugs)
Version: SVN trunk (KDE4 version)
Platform: Unlisted Binaries Linux
: NOR normal
Target Milestone: ---
Assignee: KPhotoAlbum Bugs
URL:
Keywords: junior-jobs
Depends on:
Blocks:
 
Reported: 2008-02-01 20:45 UTC by Jan Kundrát
Modified: 2012-02-13 20:30 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
This Path will inform user if write ends not succsesful (2.53 KB, patch)
2009-10-15 18:19 UTC, Kirill Kalyuzhniy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kundrát 2008-02-01 20:45:16 UTC
As suggested by Robert Krawitz on 2007-11-07, KPA should be smart when dealing 
with file I/O:


As a general principle, everything that writes data really does need
to check the return value from both the write and the close (the
write, particularly if you're using buffered I/O, may not be
synchronous), period.  There are no shortcuts.  You can't rely on
anything else monitoring free space, and there are a lot of other
reasons a write could fail (network problems, for example, if you're
using a networked filesystem).

Creating a bunch of zero length thumbnails is embarrassing.  If
writing the index.xml file has the same problem, the results could be
much more serious.
Comment 1 Jesper Pedersen 2009-07-10 17:38:35 UTC
For index.xml the trick could be first to write to another file in the same
directory, and then move the file in place. The code for writing the XML
data is in XMLDB/FileWriter.cpp (XMLDB::FileWriter::save).

You would have to find a way to simulate out of hard disk (perhaps use a
key ring for storing your data)
Comment 2 Kirill Kalyuzhniy 2009-10-15 18:19:44 UTC
Created attachment 37596 [details]
This Path will inform user if write ends not succsesful
Comment 3 Miika Turkia 2012-02-02 06:12:21 UTC
As Jesper pointed out, especially a write error on index.xml should be taken care off. Testing running out of disk situation should be quite straight forward at least with a loop back mounting a smallish file system. Steps to create:

dd if=/dev/zero of=KPhotoAlbum-test.img bs=1M count=10
sudo losetup /dev/loop0 KPhotoAlbum-test.img 
sudo mke2fs -c /dev/loop0 
mkdir KPhotoAlbum-test-mount
sudo mount /dev/loop0 KPhotoAlbum-test-mount

Now just copy a couple of files to KPhotoAlbum-test-mount and start hacking.
To unmount the fs and detach the loop do:

sudo umount KPhotoAlbum-test-mount
losetup -d /dev/oop0
Comment 4 Johannes Zarl-Zierl 2012-02-03 19:46:48 UTC
(In reply to comment #3)
> As Jesper pointed out, especially a write error on index.xml should be taken
> care off. Testing running out of disk situation should be quite straight
> forward at least with a loop back mounting a smallish file system. Steps to
> create:
> 
> dd if=/dev/zero of=KPhotoAlbum-test.img bs=1M count=10
> sudo losetup /dev/loop0 KPhotoAlbum-test.img 
> sudo mke2fs -c /dev/loop0 
> mkdir KPhotoAlbum-test-mount
> sudo mount /dev/loop0 KPhotoAlbum-test-mount
> 
> Now just copy a couple of files to KPhotoAlbum-test-mount and start hacking.
> To unmount the fs and detach the loop do:
> 
> sudo umount KPhotoAlbum-test-mount
> losetup -d /dev/oop0

Using tmpfs you can achieve this even simpler:
mkdir KPhotoAlbum-test-mount
sudo mount none -t tmpfs -o size=10m KPhotoAlbum-test-mount
(...test stuff...)
sudo umount KPhotoAlbum-test-mount
Comment 5 Miika Turkia 2012-02-13 16:52:16 UTC
Git commit 9a55cef622459a069114fb8bb4f67977bc9717ae by Miika Turkia, on behalf of Johannes Zarl.
Committed on 12/02/2012 at 21:36.
Pushed by mturkia into branch 'master'.

Better detection of write problems.

Check results when writing zip files in XMLDB::NumberedBackup.
Check results when using QFile IO in XMLDB::Filewriter and
AnnotationDialog::Dialog.

M  +14   -2    AnnotationDialog/Dialog.cpp
M  +15   -3    XMLDB/FileWriter.cpp
M  +4    -1    XMLDB/NumberedBackup.cpp

http://commits.kde.org/kphotoalbum/9a55cef622459a069114fb8bb4f67977bc9717ae