-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkiofuseapp.cpp
1150 lines (980 loc) · 48.4 KB
/
kiofuseapp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
* Copyright (c) 2003-2004 by Alexander Neundorf & Kevin 'ervin' Ottens *
* Copyright (c) 2007-2008 Vlad Codrea *
* Copyright (c) 2015 Thomas Fischer *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License. *
* *
****************************************************************************/
#include "kiofuseapp.h"
#include <signal.h>
//#include <QThread>
//#include <QMutexLocker>
#include <kdebug.h>
#include <kio/netaccess.h>
#include <kio/deletejob.h>
KioFuseApp *kioFuseApp = NULL;
//const unsigned int MAX_TIME_OPENED = 8*3600*1000 /*4000*/; // Time out for opened files in ms
KioFuseApp::KioFuseApp(const KUrl &url, const KUrl &mountPoint)
: KApplication(false), //No GUI
fhIdtoFileJobDataMutex(QMutex::Recursive),
m_baseUrl(url),
m_mountPoint(mountPoint),
m_baseUrlMutex(QMutex::Recursive),
m_mountPointMutex(QMutex::Recursive),
m_terminatedFhListMutex(QMutex::Recursive)
//m_errorTransMutex(QMutex::Recursive) // Controls error translator
//m_cacheRoot(NULL),
//m_numCached(1), // One stub (the root) is already cached in the constructor, so start counter at 1
//m_numLeafStubsCached(0), // Leaf stubs are for opened files that have no stat data
//m_cacheMutex(QMutex::Recursive) // Allow the mutex to be locked several times within the same thread
{
//QMutexLocker locker(&m_cacheMutex);
kDebug()<<"KioFuseApp ctor baseUrl: "<<m_baseUrl.prettyUrl()<<endl;
//QString root = QString("/"); // Create the cache root, which represents the root directory (/)
//m_cacheRoot = new Cache(root, Cache::innerStubType); // All files and folders will be children of this node
}
KioFuseApp::~KioFuseApp()
{
//QMutexLocker locker(&m_cacheMutex);
kDebug()<<"KioFuseApp dtor"<<endl;
foreach (FileJobData* fileJobData, fhIdtoFileJobData){
// FileJobData dtor will close the FileJob
delete fileJobData;
}
//delete m_cacheRoot; // Recursively delete the whole cache
//m_cacheRoot = NULL;
}
const KUrl& KioFuseApp::baseUrl() // Getter method for the remote base URL
{
QMutexLocker locker(&m_baseUrlMutex);
return m_baseUrl;
}
const KUrl& KioFuseApp::mountPoint() // Getter method for the remote base URL
{
QMutexLocker locker(&m_mountPointMutex);
return m_mountPoint;
}
KUrl KioFuseApp::buildRemoteUrl(const QString& path) // Create a full URL containing both the remote base and the relative path
{
QMutexLocker locker(&m_baseUrlMutex);
KUrl url = baseUrl();
/*if (path == "/"){
// Don't need to append only a "/"
// Allows files to be baseUrls
return url;
}*/
url.addPath(path);
return url;
}
KUrl KioFuseApp::buildLocalUrl(const QString& path) // Create a full URL containing both the remote base and the relative path
{
QMutexLocker locker(&m_mountPointMutex);
KUrl url = mountPoint();
url.addPath(path);
return url;
}
void KioFuseApp::storeOpenHandle(KIO::FileJob* fileJob, OpenJobHelper* openJobHelper)
{
//QMutexLocker locker(&m_cacheMutex);
FileJobData* fileJobData = new FileJobData(fileJob); //FIXME delete at random intervals
VERIFY(fileJobData->fileJob->thread() == this->thread());
uint64_t fileHandleId; // fi->fh is of type uint64_t
// Make sure we haven't run out of candidate fileHandleIds
VERIFY(fhIdtoFileJobData.size() < (RAND_MAX - 1));
//FIXME FIXME remove
//VERIFY(1==2);
fileJobData->qTime.start();
do {
fileHandleId = static_cast<uint64_t>(rand());
} while (fhIdtoFileJobData.contains(fileHandleId));
//Don't need an assert here because we're out of the while loop
fhIdtoFileJobData.insertMulti(fileHandleId, fileJobData);
kDebug()<<"fileHandleId"<<fileHandleId<<"fileJob"<<fileJob<<"&(fileJobData->jobMutex)"<<&(fileJobData->jobMutex)<<endl;
//qRegisterMetaType<uint64_t>("uint64_t");
VERIFY(QMetaObject::invokeMethod(openJobHelper, "setFileHandleId",
Q_ARG(uint64_t, fileHandleId)));
//QTimer::singleShot(0, openJobHelper, SLOT(setFileHandleId(fileHandleId)));
/*connect(this, SIGNAL(sendFileHandleId(const uint64_t&)),
openJobHelper, SLOT(setFileHandleId(const uint64_t&)),
Qt::QueuedConnection);
emit sendFileHandleId(fileHandleId);*/
/*bool addedLeafStub = m_cacheRoot->setExtraData(url, fileHandleId, fileJob);
if (addedLeafStub){
m_numLeafStubsCached++;
}*/
}
// Find the job using its ID, and prevent other threads from
// using it. Because it locks a mutex, it must be called directly
// from the client thread.
/*void KioFuseApp::lockJob(const uint64_t& fileHandleId)
{
kDebug()<<"Locking fileHandleId"<<fileHandleId<<endl;
FileJobData* fileJobData = fhIdtoFileJobData.value(fileHandleId);
if (fileJobData){
fileJobData->jobMutex.lock();
}
}
// Opposite of lockJob
void KioFuseApp::unLockJob(const uint64_t& fileHandleId)
{
kDebug()<<"Unlocking fileHandleId"<<fileHandleId<<endl;
FileJobData* fileJobData = fhIdtoFileJobData.value(fileHandleId);
if (fileJobData){
fileJobData->jobMutex.unlock();
}
}*/
// Return an opened job and reset its timer.
KIO::FileJob* KioFuseApp::checkOutJob(/*const KUrl& url,*/
const uint64_t& fileHandleId)
{
//QMutexLocker cacheLocker(&m_cacheMutex);
if (fhIdtoFileJobData.contains(fileHandleId)){
FileJobData* fileJobData = fhIdtoFileJobData.value(fileHandleId);
VERIFY(fhIdtoFileJobData.count(fileHandleId) == 1);
VERIFY(fileJobData->fileJob->thread() == this->thread());
//FIXME Fuse renames temporary files on the server. This is a FUSE bug.
/*// The urls of the file being accessed and the opened file must match
VERIFY(url.path(KUrl::RemoveTrailingSlash) ==
fileJobData->fileJob->url().path(KUrl::RemoveTrailingSlash));*/
/* if (fileJobData->qTime.elapsed() > MAX_TIME_OPENED){
kDebug()<<"Found expired fileHandleId"<<fileHandleId<<endl;
removeJob(fileHandleId, fileJobData);
fileJobData = NULL;
return NULL;
}*/
kDebug()<<"fileHandleId"<<fileHandleId<<"fileJobData"<<fileJobData<<"fileJobData->fileJob"<<fileJobData->fileJob<<endl;
//cacheLocker.unlock();
/*while (fileJobData->inUse){
kDebug()<<"fileJobData is in use, wasting some time."<<endl;
}
fileJobData->inUse = true;*/
//fileJobData->jobMutex.lock();
//cacheLocker.relock();
fileJobData->qTime.restart();
return fileJobData->fileJob;
} else {
// Didn't find the job
kDebug()<<"WARNING: Didn't find fileHandleId"<<fileHandleId<<endl;
return NULL;
}
}
// Allow other threads to use the FileJob specified by this fileHandleId
/*void KioFuseApp::checkInJob(const KUrl& url, const uint64_t& fileHandleId)
{
//QMutexLocker locker(&m_cacheMutex);
// The fileJob *must* be there if we're checking it back in
if(!fhIdtoFileJobData.contains(fileHandleId)){
kDebug()<<"WARNING: File expired: url"<<url<<endl;
return;
}
VERIFY(fhIdtoFileJobData.count(fileHandleId) == 1);
FileJobData* fileJobData = fhIdtoFileJobData.value(fileHandleId);
VERIFY(fileJobData->fileJob->thread() == this->thread());
fileJobData->qTime.restart();
//fileJobData->inUse = false;
//fileJobData->jobMutex.unlock();
}*/
void KioFuseApp::removeJob(const uint64_t& fileHandleId,
FileJobData* fileJobData, const bool& jobIsAnnulled)
{
//QMutexLocker locker(&m_cacheMutex);
//VERIFY(fileJobData->fileJob->thread() == this->thread());
kDebug()<<"fhIdtoFileJobData.size()"<<fhIdtoFileJobData.size()<<endl;
int removed = fhIdtoFileJobData.remove(fileHandleId);
VERIFY(removed == 1);
/*if (removed != 1){
kDebug()<<"WARNING: File expired: fileHandleId"<<fileHandleId<<endl;
fileJobData = NULL; // Don't delete twice
return;
}*/
fileJobData->jobIsAnnulled = jobIsAnnulled;
delete fileJobData;
fileJobData = NULL;
}
/*********** ListJob ***********/
void KioFuseApp::listJobMainThread(const KUrl& url, ListJobHelper* listJobHelper)
{
kDebug()<<"this->thread()"<<this->thread()<<endl;
KIO::ListJob* listJob = KIO::listDir(url, KIO::HideProgressInfo, true);
VERIFY(listJob->thread() == this->thread());
kDebug()<<"listJob"<<listJob<<endl;
kDebug()<<"listJob->thread()"<<listJob->thread()<<endl;
// Correlate listJob with the ListJobHelper that needs it
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(listJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(listJob),
qobject_cast<BaseJobHelper*>(listJobHelper));
// Needed to be able to use Qt::QueuedConnection
//qRegisterMetaType<KIO::UDSEntryList>("KIO::UDSEntryList");
// Send the entries to listJobHelper when they become available
connect(listJob, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList &)),
listJobHelper, SLOT(receiveEntries(KIO::Job*, const KIO::UDSEntryList &)));
// Job will be deleted when finished
connect(listJob, SIGNAL(result(KJob*)),
this, SLOT(slotResult(KJob*)));
}
void KioFuseApp::slotResult(KJob* job)
{
kDebug()<<"this->thread()"<<this->thread()<<endl;
kDebug()<<"job"<<job<<endl;
int error = job->error();
BaseJobHelper* jobHelper = m_jobToJobHelper.value(job);
// Remove job and jobHelper from map
int numJobsRemoved = m_jobToJobHelper.remove(job);
VERIFY(numJobsRemoved == 1);
VERIFY(job);
job->kill();
job = NULL;
VERIFY(QMetaObject::invokeMethod(jobHelper, "jobDone",
Q_ARG(int, error)));
/*connect(this, SIGNAL(sendJobDone(const int&)),
jobHelper, SLOT(jobDone(const int&)), Qt::QueuedConnection);
emit sendJobDone(error);*/
}
/*********** StatJob ***********/
void KioFuseApp::statJobMainThread(const KUrl& url,
StatJobHelper* statJobHelper)
{
/*KIO::StatJob* statJob = KIO::stat(url, KIO::StatJob::SourceSide,
2, KIO::HideProgressInfo);*/
KIO::StatJob* statJob = KIO::stat(url, KIO::HideProgressInfo);
kDebug()<<"url"<<url<<"statJobHelper"<<statJobHelper<<"statJob"<<statJob<<endl;
VERIFY(statJob->thread() == this->thread());
// Correlate listJob with the ListJobHelper that needs it
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(statJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(statJob),
qobject_cast<BaseJobHelper*>(statJobHelper));
// Job will be deleted when finished
connect(statJob, SIGNAL(result(KJob*)),
this, SLOT(slotStatJobResult(KJob*)));
}
void KioFuseApp::slotStatJobResult(KJob* job)
{
int error = job->error();
kDebug()<<"error"<<error<<endl;
if (error != 0) kDebug()<<job->errorString()<<endl;
BaseJobHelper* jobHelper = m_jobToJobHelper.value(job);
StatJobHelper* statJobHelper = qobject_cast<StatJobHelper*>(jobHelper);
if (job->error() == 0){
KIO::StatJob* statJob = qobject_cast<KIO::StatJob*>(job);
KIO::UDSEntry entry = statJob->statResult();
kDebug()<<"statJobHelper"<<statJobHelper<<"statJob"<<statJob<<endl;
// Needed to be able to use Qt::QueuedConnection
//qRegisterMetaType<KIO::UDSEntry>("KIO::UDSEntry");
// Send the entry to statJobHelper
VERIFY(QMetaObject::invokeMethod(statJobHelper, "receiveEntry",
Q_ARG(KIO::UDSEntry, entry)));
/*connect(this, SIGNAL(sendEntry(const KIO::UDSEntry &)),
statJobHelper, SLOT(receiveEntry(const KIO::UDSEntry &)),
Qt::QueuedConnection);
emit sendEntry(entry);*/
}
// Remove job and jobHelper from map
int numJobsRemoved = m_jobToJobHelper.remove(job);
VERIFY(numJobsRemoved == 1);
VERIFY(job);
job->kill();
job = NULL;
VERIFY(QMetaObject::invokeMethod(jobHelper, "jobDone",
Q_ARG(int, error)));
/*connect(this, SIGNAL(sendJobDone(const int&)),
jobHelper, SLOT(jobDone(const int&)), Qt::QueuedConnection);
emit sendJobDone(error);*/
}
/*********** OpenJob ***********/
void KioFuseApp::openJobMainThread(const KUrl& url, const QIODevice::OpenMode& qtMode, OpenJobHelper* openJobHelper)
{
// Will be cached and close()-ed upon POSIX release()
KIO::FileJob* fileJob = KIO::open(url, qtMode);
//fileJob->setAutoDelete(false); // We'll kill() the fileJob in the
// destructor of FileJobData or in
// slotResult.
VERIFY(fileJob->thread() == this->thread());
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(fileJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(fileJob),
qobject_cast<BaseJobHelper*>(openJobHelper));
connect(fileJob, SIGNAL(open(KIO::Job*)),
this, SLOT(fileJobOpened(KIO::Job*)));
connect(fileJob, SIGNAL(canceled(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
connect(fileJob, SIGNAL(finished(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
connect(fileJob, SIGNAL(result(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
// FIXME for testing purposes, only
connect(fileJob, SIGNAL(mimetype(KIO::Job*, const QString&)),
this, SLOT(slotMimetype(KIO::Job*, const QString&)));
}
void KioFuseApp::fileJobOpened(KIO::Job* job)
{
KIO::FileJob* fileJob = qobject_cast<KIO::FileJob*>(job);
kDebug()<<"fileJob->thread()"<<fileJob->thread()<<"this->thread()"<<this->thread()<<endl;
// Prevent fileJob calling jobErrorReadWrite() after the file is already opened
disconnect(fileJob, 0, this, SLOT(jobErrorReadWrite(KJob*)));
int error = job->error();
BaseJobHelper* jobHelper = m_jobToJobHelper.value(qobject_cast<KJob*>(job));
OpenJobHelper* openJobHelper = qobject_cast<OpenJobHelper*>(jobHelper);
if (!error){
// Store fh in cache and in the openJobHelper
kioFuseApp->storeOpenHandle(fileJob, openJobHelper);
} else
kDebug()<<job->errorString();
// Remove job and jobHelper from map
int numJobsRemoved = m_jobToJobHelper.remove(qobject_cast<KJob*>(job));
VERIFY(numJobsRemoved == 1);
VERIFY(QMetaObject::invokeMethod(openJobHelper, "jobDone",
Q_ARG(int, error)));
/*connect(this, SIGNAL(sendJobDone(const int&)),
openJobHelper, SLOT(jobDone(const int&)), Qt::QueuedConnection);
emit sendJobDone(error);*/
}
// The difference between jobErrorReadWrite and jobErrorOpen is that
// jobErrorOpen kills the job by calling slotResult while jobErrorReadWrite
// doesn't.
/*void KioFuseApp::jobErrorOpen(KJob* job)
{
KIO::FileJob* fileJob = qobject_cast<KIO::FileJob*>(job);
disconnect(fileJob, 0, this, SLOT(jobErrorOpen(KJob*)));
// If there's no error, ignore and don't call slotResult.
// fileJobOpened will handle it
if (job->error()){
kDebug()<<"Error opening fileJob. fileJob"<<fileJob<<"job->error()"<<job->error()<<endl;
VERIFY(QMetaObject::invokeMethod(this, "slotResult",
Q_ARG(KJob*, job)));
}
}*/
/*// The difference between jobErrorReadWrite and jobErrorOpen is that
// jobErrorOpen kills the job by calling slotResult while jobErrorReadWrite
// doesn't.*/
// The difference between jobErrorReadWrite and slotResult is that slotResult
// kills the job, while jobErrorReadWrite does not. This is because a job
// is already finished after it gives an error, and attempting to kill() it
// can cause a crash.
void KioFuseApp::jobErrorReadWrite(KJob* job)
{
KIO::FileJob* fileJob = qobject_cast<KIO::FileJob*>(job);
disconnect(fileJob, 0, this, SLOT(jobErrorReadWrite(KJob*)));
int error = job->error();
// If there's no error, ignore and don't call slotResult.
// fileJobOpened will handle it
if (error){
kDebug()<<"Error reading/writing to fileJob. error"<<error<<endl<<job->errorString();
BaseJobHelper* jobHelper = m_jobToJobHelper.value(job);
// Remove job and jobHelper from map but don't kill the job
int numJobsRemoved = m_jobToJobHelper.remove(job);
VERIFY(numJobsRemoved == 1);
VERIFY(QMetaObject::invokeMethod(jobHelper, "jobDone",
Q_ARG(int, error)));
}
}
// FIXME for testing purposes, only
void KioFuseApp::slotMimetype(KIO::Job* job, const QString& type)
{
KIO::FileJob* fileJob = qobject_cast<KIO::FileJob*>(job);
disconnect(fileJob, 0, this, SLOT(slotMimetype(KIO::Job*, const QString&)));
kDebug()<<"type"<<type<<endl;
}
/*********** LockHelper ***********/
void KioFuseApp::findMutexMainThread(const uint64_t& fileHandleId, LockHelper* lockHelper)
{
QMutex* jobMutex;
int error = 0;
FileJobData* fileJobData = fhIdtoFileJobData.value(fileHandleId);
if (fileJobData){
jobMutex = &(fileJobData->jobMutex);
} else {
jobMutex = NULL;
error = KIO::ERR_DOES_NOT_EXIST;
}
VERIFY(QMetaObject::invokeMethod(lockHelper, "setJobMutex",
Q_ARG(QMutex*, jobMutex),
Q_ARG(int, error)));
/*connect(this, SIGNAL(sendJobMutex(QMutex*, const int&)),
lockHelper, SLOT(setJobMutex(QMutex*, const int&)), Qt::QueuedConnection);
emit sendJobMutex(jobMutex, error);*/
}
/*********** Seek for Read ***********/
void KioFuseApp::seekReadMainThread(const uint64_t& fileHandleId, const off_t& offset, ReadJobHelper* readJobHelper)
{
//FIXME trying out
//FIXME don't need because of QMetaObject::invokeMethod
//disconnect(readJobHelper, 0, this, 0);
//readJobHelper->disconnect();
KIO::FileJob* fileJob = checkOutJob(/*readJobHelper->url(),*/ fileHandleId);
if (!fileJob){
kDebug()<<"fileJob not found. fileHandleId"<<fileHandleId<<endl;
VERIFY(QMetaObject::invokeMethod(readJobHelper, "jobDone",
Q_ARG(int, KIO::ERR_COULD_NOT_READ)));
/*connect(this, SIGNAL(sendJobDone(const int&)),
readJobHelper, SLOT(jobDone(const int&)), Qt::QueuedConnection);
emit sendJobDone(KIO::ERR_COULD_NOT_READ);*/
return;
}
VERIFY(fileJob->thread() == this->thread());
kDebug()<<"fileJob"<<fileJob<<"readJobHelper"<<readJobHelper<<endl;
kDebug()<<"m_jobToJobHelper.count(qobject_cast<KJob*>(fileJob))"<<m_jobToJobHelper.count(qobject_cast<KJob*>(fileJob))<<endl;
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(fileJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(fileJob),
qobject_cast<BaseJobHelper*>(readJobHelper));
// Needed by Qt::QueuedConnection
//qRegisterMetaType<KIO::filesize_t>("KIO::filesize_t");
connect(fileJob, SIGNAL(position(KIO::Job*, KIO::filesize_t)),
this, SLOT(slotReadPosition(KIO::Job*, KIO::filesize_t)));
connect(fileJob, SIGNAL(canceled(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
connect(fileJob, SIGNAL(finished(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
connect(fileJob, SIGNAL(result(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
fileJob->seek(static_cast<KIO::filesize_t>(offset));
}
void KioFuseApp::slotReadPosition(KIO::Job* job, KIO::filesize_t pos)
{
KIO::FileJob* fileJob = qobject_cast<KIO::FileJob*>(job);
// Prevent FileJob::position() signal from being triggered multiple times
// upon subsequent seeks. Also prevents fileJob from calling
// jobErrorReadWrite() after we've received the position.
disconnect(fileJob, 0, this, 0);
kDebug()<<"job"<<job<<"job->thread()"<<job->thread()<<"pos"<<pos<<endl;
VERIFY(m_jobToJobHelper.contains(qobject_cast<KJob*>(job)));
BaseJobHelper* jobHelper = m_jobToJobHelper.value(qobject_cast<KJob*>(job));
ReadJobHelper* readJobHelper = qobject_cast<ReadJobHelper*>(jobHelper);
kDebug()<<"readJobHelper"<<readJobHelper<<endl;
// Remove job and jobHelper from map
int numJobsRemoved = m_jobToJobHelper.remove(qobject_cast<KJob*>(job));
VERIFY(numJobsRemoved == 1);
// Needed by Qt::QueuedConnection
//qRegisterMetaType<off_t>("off_t");
// Send the position to readJobHelper
VERIFY(QMetaObject::invokeMethod(readJobHelper, "receivePosition",
Q_ARG(off_t, static_cast<off_t>(pos)),
Q_ARG(int, job->error()),
Q_ARG(KIO::FileJob*, fileJob)));
/*connect(this, SIGNAL(sendPosition(const off_t&, const int&, KIO::FileJob*)),
readJobHelper, SLOT(receivePosition(const off_t&, const int&, KIO::FileJob*)),
Qt::QueuedConnection);
emit sendPosition(static_cast<off_t>(pos), job->error(), fileJob);*/
}
void KioFuseApp::readMainThread(KIO::FileJob* fileJob, const size_t& size, ReadJobHelper* readJobHelper)
{
kDebug()<<"size"<<size<<endl;
//kDebug()<<"readJobHelper"<<readJobHelper<<endl;
//FIXME trying out
//Not needed because of QMetaObject::invokeMethod
//disconnect(readJobHelper, 0, this, 0);
//readJobHelper->disconnect();
VERIFY(fileJob->thread() == this->thread());
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(fileJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(fileJob),
qobject_cast<BaseJobHelper*>(readJobHelper));
connect(fileJob, SIGNAL(data(KIO::Job*, const QByteArray&)),
this, SLOT(slotData(KIO::Job*, const QByteArray&)));
connect(fileJob, SIGNAL(canceled(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
connect(fileJob, SIGNAL(finished(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
connect(fileJob, SIGNAL(result(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
fileJob->read(static_cast<KIO::filesize_t>(size));
}
void KioFuseApp::slotData(KIO::Job* job, const QByteArray& data)
{
kDebug()<<"data"<<data<<"job"<<job<<endl;
KIO::FileJob* fileJob = qobject_cast<KIO::FileJob*>(job);
// Prevent FileJob::data() signal from being triggered multiple times
// upon subsequent reads. Also prevents fileJob from calling
// jobErrorReadWrite() after we've received the data.
disconnect(fileJob, 0, this, 0);
//fileJob->disconnect();
BaseJobHelper* jobHelper = m_jobToJobHelper.value(qobject_cast<KJob*>(job));
ReadJobHelper* readJobHelper = qobject_cast<ReadJobHelper*>(jobHelper);
VERIFY(readJobHelper);
checkOutJob(/*readJobHelper->url(),*/ readJobHelper->fileHandleId());
// Remove job and jobHelper from map
int numJobsRemoved = m_jobToJobHelper.remove(qobject_cast<KJob*>(job));
/*if (numJobsRemoved != 1)
{
kDebug()<<"numJobsRemoved"<<numJobsRemoved<<"readJobHelper->fileHandleId()"<<readJobHelper->fileHandleId()<<endl;
}*/
VERIFY(numJobsRemoved == 1);
VERIFY(QMetaObject::invokeMethod(readJobHelper, "receiveData",
Q_ARG(QByteArray, data),
Q_ARG(int, job->error())));
/*connect(this, SIGNAL(sendData(const QByteArray&, const int&)),
readJobHelper, SLOT(receiveData(const QByteArray&, const int&)),
Qt::QueuedConnection);
emit sendData(data, job->error());*/
}
/*********** Seek for Write ***********/
void KioFuseApp::seekWriteMainThread(const uint64_t& fileHandleId, const off_t& offset, WriteJobHelper* writeJobHelper)
{
KIO::FileJob* fileJob = checkOutJob(/*writeJobHelper->url(),*/ fileHandleId);
if (!fileJob){
kDebug()<<"fileJob not found. fileHandleId"<<fileHandleId<<endl;
VERIFY(QMetaObject::invokeMethod(writeJobHelper, "jobDone",
Q_ARG(int, KIO::ERR_COULD_NOT_READ)));
/*connect(this, SIGNAL(sendJobDone(const int&)),
writeJobHelper, SLOT(jobDone(const int&)), Qt::QueuedConnection);
emit sendJobDone(KIO::ERR_COULD_NOT_READ);*/
return;
}
VERIFY(fileJob->thread() == this->thread());
kDebug()<<"fileJob"<<fileJob<<"fileJob->thread()"<<fileJob->thread()<<endl;
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(fileJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(fileJob),
qobject_cast<BaseJobHelper*>(writeJobHelper));
// Needed by Qt::QueuedConnection
//qRegisterMetaType<KIO::filesize_t>("KIO::filesize_t");
connect(fileJob, SIGNAL(position(KIO::Job*, KIO::filesize_t)),
this, SLOT(slotWritePosition(KIO::Job*, KIO::filesize_t)));
connect(fileJob, SIGNAL(canceled(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
connect(fileJob, SIGNAL(finished(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
connect(fileJob, SIGNAL(result(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
fileJob->seek(static_cast<KIO::filesize_t>(offset));
}
void KioFuseApp::slotWritePosition(KIO::Job* job, KIO::filesize_t pos)
{
KIO::FileJob* fileJob = qobject_cast<KIO::FileJob*>(job);
// Prevent FileJob::position() signal from being triggered multiple times
// upon subsequent seeks. Also prevents fileJob from calling
// jobErrorReadWrite() after we've received the position.
disconnect(fileJob, 0, this, 0);
//fileJob->disconnect();
kDebug()<<"job"<<job<<"job->thread()"<<job->thread()<<endl;
VERIFY(m_jobToJobHelper.contains(qobject_cast<KJob*>(job)));
BaseJobHelper* jobHelper = m_jobToJobHelper.value(qobject_cast<KJob*>(job));
WriteJobHelper* writeJobHelper = qobject_cast<WriteJobHelper*>(jobHelper);
// Remove job and jobHelper from map
int numJobsRemoved = m_jobToJobHelper.remove(qobject_cast<KJob*>(job));
VERIFY(numJobsRemoved == 1);
// Needed by Qt::QueuedConnection
//qRegisterMetaType<off_t>("off_t");
// Send the position to writeJobHelper
VERIFY(QMetaObject::invokeMethod(writeJobHelper, "receivePosition",
Q_ARG(off_t, static_cast<off_t>(pos)),
Q_ARG(int, job->error()),
Q_ARG(KIO::FileJob*, fileJob)));
/*connect(this, SIGNAL(sendPosition(const off_t&, const int&, KIO::FileJob*)),
writeJobHelper, SLOT(receivePosition(const off_t&, const int&, KIO::FileJob*)),
Qt::QueuedConnection);
emit sendPosition(static_cast<off_t>(pos), job->error(), fileJob);*/
}
void KioFuseApp::writeMainThread(KIO::FileJob* fileJob, const QByteArray& data, WriteJobHelper* writeJobHelper)
{
kDebug()<<"writeJobHelper"<<writeJobHelper<<endl;
VERIFY(fileJob->thread() == this->thread());
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(fileJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(fileJob),
qobject_cast<BaseJobHelper*>(writeJobHelper));
// Needed by Qt::QueuedConnection
//qRegisterMetaType<KIO::filesize_t>("KIO::filesize_t");
connect(fileJob, SIGNAL(written(KIO::Job*, const KIO::filesize_t&)),
this, SLOT(slotWritten(KIO::Job*, const KIO::filesize_t&)));
connect(fileJob, SIGNAL(canceled(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
connect(fileJob, SIGNAL(finished(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
connect(fileJob, SIGNAL(result(KJob*)),
this, SLOT(jobErrorReadWrite(KJob*)));
fileJob->write(data);
}
void KioFuseApp::slotWritten(KIO::Job* job, const KIO::filesize_t& written)
{
kDebug()<<"written"<<written<<endl;
KIO::FileJob* fileJob = qobject_cast<KIO::FileJob*>(job);
// Prevent FileJob::written() signal from being triggered multiple times
// upon subsequent reads. Also prevents fileJob from calling
// jobErrorReadWrite() after we've received the number of bytes written.
disconnect(fileJob, 0, this, 0);
//fileJob->disconnect();
BaseJobHelper* jobHelper = m_jobToJobHelper.value(qobject_cast<KJob*>(job));
WriteJobHelper* writeJobHelper = qobject_cast<WriteJobHelper*>(jobHelper);
VERIFY(writeJobHelper);
checkOutJob(/*writeJobHelper->url(),*/ writeJobHelper->fileHandleId());
// Remove job and jobHelper from map
int numJobsRemoved = m_jobToJobHelper.remove(qobject_cast<KJob*>(job));
VERIFY(numJobsRemoved == 1);
// Needed by Qt::QueuedConnection
//qRegisterMetaType<size_t>("size_t");
VERIFY(QMetaObject::invokeMethod(writeJobHelper, "receiveWritten",
Q_ARG(size_t,
static_cast<size_t>(written)),
Q_ARG(int, job->error())));
/*connect(this, SIGNAL(sendWritten(const size_t&, const int&)),
writeJobHelper, SLOT(receiveWritten(const size_t&, const int&)),
Qt::QueuedConnection);
emit sendWritten(static_cast<size_t>(written), job->error());*/
}
/*********** MkDir ***********/
void KioFuseApp::mkDirMainThread(const KUrl& url, const mode_t& mode,
MkDirHelper* mkDirHelper)
{
KIO::SimpleJob* simpleJob = KIO::mkdir(url, mode);
VERIFY(simpleJob->thread() == this->thread());
// Correlate SimpleJob with the MkDirHelper that needs it
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(simpleJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(simpleJob),
qobject_cast<BaseJobHelper*>(mkDirHelper));
kDebug()<<"mode"<<mode<<url<<url<<endl;
connect(simpleJob, SIGNAL(result(KJob*)),
this, SLOT(slotResult(KJob*)));
}
/*********** MkNod ***********/
void KioFuseApp::mkNodMainThread(const KUrl& url, const mode_t& mode,
MkNodHelper* mkNodHelper)
{
KTemporaryFile* temp = new KTemporaryFile();
temp->setAutoRemove(false); // Must remove manually in slotMkNodResult()
// if move fails
temp->open();
// FIXME file_move ignores mode, BAD! file_copy seems to work OK.
KIO::FileCopyJob* fileCopyJob = KIO::file_move(temp->fileName(), url, mode /*33188*/,
KIO::Overwrite | KIO::HideProgressInfo);
VERIFY(fileCopyJob->thread() == this->thread());
// Correlate temp file with job
VERIFY(m_jobToTempFile.count(qobject_cast<KJob*>(fileCopyJob)) == 0);
m_jobToTempFile.insertMulti(qobject_cast<KJob*>(fileCopyJob), temp);
// Correlate FileCopyJob with the MkNodHelper that needs it
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(fileCopyJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(fileCopyJob),
qobject_cast<BaseJobHelper*>(mkNodHelper));
kDebug()<<"mode"<<mode<<"temp.fileName()"<<temp->fileName()<<url<<url<<endl;
connect(fileCopyJob, SIGNAL(result(KJob*)),
this, SLOT(slotMkNodResult(KJob*)));
}
void KioFuseApp::slotMkNodResult(KJob* job)
{
int error = job->error();
// Delete the temp file if there was an error
KTemporaryFile* temp = m_jobToTempFile.value(job);
VERIFY(temp);
if (error){
temp->setAutoRemove(true);
}
BaseJobHelper* jobHelper = m_jobToJobHelper.value(job);
// Remove job and temp file from map
int numTempFilesRemoved = m_jobToTempFile.remove(job);
VERIFY(numTempFilesRemoved == 1);
delete(temp);
// Remove job and jobHelper from map
int numJobsRemoved = m_jobToJobHelper.remove(job);
VERIFY(numJobsRemoved == 1);
VERIFY(job);
job->kill();
job = NULL;
VERIFY(QMetaObject::invokeMethod(jobHelper, "jobDone",
Q_ARG(int, error)));
/*connect(this, SIGNAL(sendJobDone(const int&)),
jobHelper, SLOT(jobDone(const int&)), Qt::QueuedConnection);
emit sendJobDone(error);*/
}
/*********** SymLink ***********/
void KioFuseApp::symLinkMainThread(const KUrl& source, const KUrl& dest,
SymLinkHelper* symLinkHelper)
{
kDebug()<<"source.path()"<<source.path()<<"dest"<<dest<<endl;
KIO::SimpleJob* simpleJob = KIO::symlink(source.path(), dest,
KIO::HideProgressInfo);
VERIFY(simpleJob->thread() == this->thread());
// Correlate SimpleJob with the SymLinkHelper that needs it
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(simpleJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(simpleJob),
qobject_cast<BaseJobHelper*>(symLinkHelper));
connect(simpleJob, SIGNAL(result(KJob*)),
this, SLOT(slotResult(KJob*)));
}
/*********** ReName ***********/
void KioFuseApp::reNameMainThread(const KUrl& source, const KUrl& dest,
ReNameHelper* reNameHelper)
{
KIO::FileCopyJob* fileCopyJob = KIO::file_move(source, dest, -1,
KIO::Overwrite | KIO::HideProgressInfo);
VERIFY(fileCopyJob->thread() == this->thread());
// Correlate FileCopyJob with the ReNameHelper that needs it
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(fileCopyJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(fileCopyJob),
qobject_cast<BaseJobHelper*>(reNameHelper));
connect(fileCopyJob, SIGNAL(result(KJob*)),
this, SLOT(slotResult(KJob*)));
}
/*********** ChMod ***********/
void KioFuseApp::chModMainThread(const KUrl& url, const mode_t& mode,
ChModHelper* chModHelper)
{
KIO::SimpleJob* simpleJob = KIO::chmod(url, mode);
VERIFY(simpleJob->thread() == this->thread());
// Correlate SimpleJob with the ChModHelper that needs it
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(simpleJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(simpleJob),
qobject_cast<BaseJobHelper*>(chModHelper));
kDebug()<<"mode"<<mode<<endl;
connect(simpleJob, SIGNAL(result(KJob*)),
this, SLOT(slotResult(KJob*)));
}
/*********** UnLink ***********/
void KioFuseApp::unLinkMainThread(const KUrl& url, UnLinkHelper* unLinkHelper)
{
KIO::DeleteJob* deleteJob = KIO::del(url, KIO::HideProgressInfo);
VERIFY(deleteJob->thread() == this->thread());
// Correlate DeleteJob with the UnLinkHelper that needs it
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(deleteJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(deleteJob),
qobject_cast<BaseJobHelper*>(unLinkHelper));
kDebug()<<"url"<<url<<endl;
connect(deleteJob, SIGNAL(result(KJob*)),
this, SLOT(slotResult(KJob*)));
}
/*********** Release ***********/
void KioFuseApp::releaseJobMainThread(/*const KUrl& url,*/
const uint64_t& fileHandleId,
const bool& jobIsAnnulled,
ReleaseJobHelper* releaseJobHelper)
{
int error;
//QMutexLocker locker(&m_cacheMutex);
if (fhIdtoFileJobData.contains(fileHandleId)){
FileJobData* fileJobData = fhIdtoFileJobData.value(fileHandleId);
//kDebug()<<"fileJobData->fileJob->thread()"<<fileJobData->fileJob->thread()<<"this->thread()"<<this->thread()<<endl;
//VERIFY(fileJobData->fileJob->thread() == this->thread());
//FIXME Fuse renames temporary files on the server. This is a FUSE bug.
/*// The urls of the file being accessed and the opened file must match
VERIFY(url.path(KUrl::RemoveTrailingSlash) ==
fileJobData->fileJob->url().path(KUrl::RemoveTrailingSlash));*/
removeJob(fileHandleId, fileJobData, jobIsAnnulled);
fileJobData = NULL;
error = 0;
} else {
// FIXME There should be an error KIO::ERR_ALREADY_CLOSED
error = KIO::ERR_DOES_NOT_EXIST;
}
VERIFY(QMetaObject::invokeMethod(releaseJobHelper, "jobDone",
Q_ARG(int, error)));
/*connect(this, SIGNAL(sendJobDone(const int&)),
releaseJobHelper, SLOT(jobDone(const int&)), Qt::QueuedConnection);
emit sendJobDone(error);*/
}
/*********** ChTime ***********/
void KioFuseApp::chTimeMainThread(const KUrl& url, const QDateTime& dt,
ChTimeHelper* chTimeHelper)
{
KIO::SimpleJob* simpleJob = KIO::setModificationTime(url, dt);
VERIFY(simpleJob->thread() == this->thread());
// Correlate SimpleJob with the ChTimeHelper that needs it
VERIFY(m_jobToJobHelper.count(qobject_cast<KJob*>(simpleJob)) == 0);
m_jobToJobHelper.insertMulti(qobject_cast<KJob*>(simpleJob),
qobject_cast<BaseJobHelper*>(chTimeHelper));
connect(simpleJob, SIGNAL(result(KJob*)),
this, SLOT(slotResult(KJob*)));
}
void KioFuseApp::setUpTypes()
{
qRegisterMetaType<uint64_t>("uint64_t");
qRegisterMetaType<KIO::UDSEntryList>("KIO::UDSEntryList");
qRegisterMetaType<KIO::UDSEntry>("KIO::UDSEntry");
qRegisterMetaType<KIO::filesize_t>("KIO::filesize_t");
qRegisterMetaType<off_t>("off_t");
qRegisterMetaType<size_t>("size_t");
qRegisterMetaType<QIODevice::OpenMode>("QIODevice::OpenMode");
qRegisterMetaType<mode_t>("mode_t");
qRegisterMetaType<ListJobHelper*>("ListJobHelper*");
qRegisterMetaType<StatJobHelper*>("StatJobHelper*");
qRegisterMetaType<OpenJobHelper*>("OpenJobHelper*");
qRegisterMetaType<ReadJobHelper*>("ReadJobHelper*");
qRegisterMetaType<WriteJobHelper*>("WriteJobHelper*");
qRegisterMetaType<MkNodHelper*>("MkNodHelper*");
qRegisterMetaType<SymLinkHelper*>("SymLinkHelper*");
qRegisterMetaType<ReNameHelper*>("ReNameHelper*");
qRegisterMetaType<ChModHelper*>("ChModHelper*");
qRegisterMetaType<ReleaseJobHelper*>("ReleaseJobHelper*");
qRegisterMetaType<MkDirHelper*>("MkDirHelper*");
qRegisterMetaType<UnLinkHelper*>("UnLinkHelper*");
qRegisterMetaType<ChTimeHelper*>("ChTimeHelper*");
qRegisterMetaType<LockHelper*>("LockHelper*");
qRegisterMetaType<QMutex*>("QMutex*");
qRegisterMetaType<KJob*>("KJob*");
qRegisterMetaType<KIO::FileJob*>("KIO::FileJob*");
}
/*void KioFuseApp::setUpErrorTranslator()
{
KIOErrToSysError.insert(KIO::ERR_CANNOT_OPEN_FOR_READING, EIO);
KIOErrToSysError.insert(KIO::ERR_CANNOT_OPEN_FOR_WRITING, EIO);
KIOErrToSysError.insert(KIO::ERR_CANNOT_LAUNCH_PROCESS, EPERM);
KIOErrToSysError.insert(KIO::ERR_INTERNAL, EPROTO);
KIOErrToSysError.insert(KIO::ERR_MALFORMED_URL, EBADF);
KIOErrToSysError.insert(KIO::ERR_UNSUPPORTED_PROTOCOL, ENOPROTOOPT);
KIOErrToSysError.insert(KIO::ERR_NO_SOURCE_PROTOCOL, ENOPROTOOPT);
KIOErrToSysError.insert(KIO::ERR_UNSUPPORTED_ACTION, ENOTTY);
KIOErrToSysError.insert(KIO::ERR_IS_DIRECTORY, EISDIR);
KIOErrToSysError.insert(KIO::ERR_IS_FILE, EEXIST);
KIOErrToSysError.insert(KIO::ERR_DOES_NOT_EXIST, ENOENT);
KIOErrToSysError.insert(KIO::ERR_FILE_ALREADY_EXIST, EEXIST);
KIOErrToSysError.insert(KIO::ERR_DIR_ALREADY_EXIST, EEXIST);
KIOErrToSysError.insert(KIO::ERR_UNKNOWN_HOST, EHOSTUNREACH);
KIOErrToSysError.insert(KIO::ERR_ACCESS_DENIED, EACCES);
KIOErrToSysError.insert(KIO::ERR_WRITE_ACCESS_DENIED, EACCES);
KIOErrToSysError.insert(KIO::ERR_CANNOT_ENTER_DIRECTORY, ENOENT);
KIOErrToSysError.insert(KIO::ERR_PROTOCOL_IS_NOT_A_FILESYSTEM, EPROTOTYPE);
KIOErrToSysError.insert(KIO::ERR_CYCLIC_LINK, ELOOP);
KIOErrToSysError.insert(KIO::ERR_USER_CANCELED, ECANCELED);
KIOErrToSysError.insert(KIO::ERR_CYCLIC_COPY, ELOOP);
KIOErrToSysError.insert(KIO::ERR_COULD_NOT_CREATE_SOCKET, ENOTCONN);
KIOErrToSysError.insert(KIO::ERR_COULD_NOT_CONNECT, ENOTCONN);
KIOErrToSysError.insert(KIO::ERR_CONNECTION_BROKEN, ENOTCONN);