Bug 477096

Summary: KJob::NoError when KIO::Overwrite with KIO::file_copy a file that is chattr +i
Product: [Frameworks and Libraries] frameworks-kio Reporter: Philip Van Hoof <philip>
Component: generalAssignee: KIO Bugs <kio-bugs-null>
Status: REPORTED ---    
Severity: normal CC: kdelibs-bugs-null, philip
Priority: NOR    
Version First Reported In: 5.105.0   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Philip Van Hoof 2023-11-16 13:55:46 UTC
SUMMARY
KIO::file_copy will not report 'Operation not permitted' as a result of chattr +i as not a KJob::NoError on job->error().

STEPS TO REPRODUCE
1. Make a file /home/user/test.txt
2. chattr +i /home/user/test.txt
3.  Run this code snippet:


QPointer<KIO::FileCopyJob> const moveJob = KIO::file_copy( QUrl::fromLocalFile( "/home/user/test.txt" ), QUrl::fromLocalFile( "/home/user/target.txt" ), -1, KIO::HideProgressInfo | KIO::Overwrite );

connect( moveJob.data(), &KJob::result, this, [ moveJob]( KJob* job )
	{
		bool failed = false;
		if ( !moveJob ) {
			qWarning() << "Failed A";
		} else {
			if ( moveJob->error() != KJob::NoError && job->error() != KJob::NoError )
			{
				qWarning() << "Failed B";
			} else {
				qWarning() << "Succeeded";
			}
		}
	} );
	
OBSERVED RESULT
* kf.kio.workers.file, Warning: Couldn't remove original dest "/home/user/test.txt" ( Operation not permitted )
* kf.kio.workers.file, Warning: Couldn't rename "/home/user/test.txt.part" to "/home/user/test.txt" ( Operation not permitted )
* Succeeded
* a unexpected new file called /home/user/test.txt.part in /home/user

EXPECTED RESULT
Failed B

SOFTWARE/OS VERSIONS
KIO: kio-5.105.0-619.67
Windows: n/a
macOS: n/a
Linux/KDE Plasma: n/a
KDE Plasma Version: n/a
KDE Frameworks Version: n/a
Qt Version: 5.8

ADDITIONAL INFORMATION
Comment 1 Philip Van Hoof 2023-11-16 14:01:19 UTC
We had similar issues with  KIO::file_move where there would be a .part file and yet it was reported as KJob::NoError. This I could however not reproduce by utilizing chattr +i. Whereas with KIO::file_copy I can. I suspect here it was an actual I/O problem. But KIO anyway didn't report it on job->error().
Comment 2 Philip Van Hoof 2023-11-16 14:04:30 UTC
A log entry we still have from when this happened with KIO::file_move was the following:

kf.kio.workers.file, Warning: Couldn't rename "/mnt/max/Testdateien/NeuSyntaxM19/Vorstellung/02_WHILE-Schleife.h.part" to "/mnt/max/Testdateien/NeuSyntaxM19/Vorstellung/02_WHILE-Schleife.h" ( No such file or directory ) (in :0, Fnc.: )

Noting that /mnt/max was a smbmounted Samba file share at the time (it could be that Vorstellung or Testdateien became temporarily unavailable). the warning 'Couldn't rename' however indicates that KIO::file_move saw it. It should have reported something different than KJob::NoError.

Also here a .part file was left.
Comment 3 Philip Van Hoof 2023-11-16 14:07:45 UTC
ps. In steps to reproduce I meant  chattr +i /home/user/target.txt of course.