By default, Bugzilla does not search the list of RESOLVED bugs.
You can force it to do so by putting the upper-case word ALL in front of your search query, e.g.: ALL tdelibs
We recommend searching for bugs this way, as you may discover that your bug has already been resolved and fixed in a later release.
Bug 2729 - Trash sometimes shows empty when deleting files
Summary: Trash sometimes shows empty when deleting files
Status: RESOLVED FIXED
Alias: None
Product: TDE
Classification: Unclassified
Component: tdebase (show other bugs)
Version: R14.0.x [Trinity]
Hardware: Other Linux
: P5 normal
Assignee: Michele Calgaro
URL:
Depends on:
Blocks: R14.0.5
  Show dependency treegraph
 
Reported: 2016-11-17 05:12 CST by Q4OS Team
Modified: 2018-04-26 01:42 CDT (History)
5 users (show)

See Also:
Compiler Version:
TDE Version String:
Application Version:
Application Name:


Attachments
Trash sometimes shows empty when deleting files (806.29 KB, video/mp4)
2016-11-17 05:12 CST, Q4OS Team
Details
good when trash is updated (22.72 KB, text/plain)
2017-01-30 16:25 CST, deloptes
Details
bad when trash is not updated (18.64 KB, text/plain)
2017-01-30 16:26 CST, deloptes
Details
A simple solution to reflect the status - the price is an overhead (534 bytes, patch)
2018-04-10 13:33 CDT, deloptes
Details | Diff
A simple solution to reflect the status - the price is an overhead (512 bytes, patch)
2018-04-10 13:47 CDT, deloptes
Details | Diff
A simple solution to reflect the status - the price is an overhead (514 bytes, patch)
2018-04-10 17:18 CDT, deloptes
Details | Diff
A simple solution to reflect the status (514 bytes, patch)
2018-04-10 17:20 CDT, deloptes
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Q4OS Team 2016-11-17 05:12:59 CST
Created attachment 2744 [details]
Trash sometimes shows empty when deleting files

Tested on a real hardware as well as in Virtualbox. As the video clip will shows, sometimes when files are deleted using konqueror-right click->Move to Trash the trash still shows as being empty.

Exact steps to reproduce:
- Fresh TDE stable (14.0.4) installation on Debian Jessie.
- Create two test '.txt' files
- Move the first file to trash using konqueror-right click->Move to Trash
- Empty trash from right mouse click context menu
- Move the second file to trash using konqueror-right click->Move to Trash
- See the bug: Trash still shows as being empty, and cannot be emptied from context menu
Comment 1 Michele Calgaro 2016-11-18 21:44:46 CST
Confirmed.
Comment 2 deloptes 2017-01-03 16:33:06 CST
DnD seems not affected. Just the move-to-trash from the right-mouse-click menu in konq
Comment 3 deloptes 2017-01-03 17:38:24 CST
I don't have the time into look into it, but here is the essence of the issue

In konq_popupmenu.cc it reads the value for Empty

    if ( isCurrentTrash )
    {
        act = new TDEAction( i18n( "&Empty Trash Bin" ), "emptytrash", 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupEmptyTrashBin() ), &m_ownActions, "empytrash" );
        KSimpleConfig trashConfig( "trashrc", true );
        trashConfig.setGroup( "Status" );
        act->setEnabled( !trashConfig.readBoolEntry( "Empty", true ) );
        addAction( act );
    }

It looks like that it does not always update the value for Empty, which should be done here in fileAdded

trashimpl.cpp
	void TrashImpl::fileAdded()
	{
	m_config.setGroup( "Status" );
	if ( m_config.readBoolEntry( "Empty", true ) == true ) {
		m_config.writeEntry( "Empty", false );
		m_config.sync();
	}
	// The apps showing the trash (e.g. kdesktop) will be notified
	// of this change when KDirNotify::FilesAdded("trash:/") is emitted,
	// which will be done by the job soon after this.
	}
	
	void TrashImpl::fileRemoved()
	{
	if ( isEmpty() ) {
		m_config.setGroup( "Status" );
		m_config.writeEntry( "Empty", true );
		m_config.sync();
	}
	// The apps showing the trash (e.g. kdesktop) will be notified
	// of this change when KDirNotify::FilesRemoved(...) is emitted,
	// which will be done by the job soon after this.
	}

Which gives the question why it works only the first time.
If you restore the file and delete it, it works again.

regards
Comment 4 deloptes 2017-01-30 16:25:45 CST
Created attachment 2752 [details]
good when trash is updated


In successful scenario there is notification emitted RemoteDirNotify::toRemoteURL(trash:/), which would end in an update- trashrc is not updated (emtpy remains true).
I attach the good and the bad scenario logs, just to keep in mind where I was and perhaps soneone can explain why it looks so different.


media tdeioslave: ()
remote tdeioslave: RemoteDirNotify::FilesAdded
remote tdeioslave: RemoteDirNotify::toRemoteURL(system:/users/emanoil/test/)
remote tdeioslave: result => KURL()
media tdeioslave: MediaDirNotify::toMediaURL(trash:/)
media tdeioslave: MediaList::list()
media tdeioslave: ()
remote tdeioslave: RemoteDirNotify::FilesAdded
remote tdeioslave: RemoteDirNotify::toRemoteURL(trash:/)
remote tdeioslave: result => KURL()
tdeio_uiserver: UIServer::jobFinished id=31



media tdeioslave: ()
remote tdeioslave: RemoteDirNotify::FilesAdded
remote tdeioslave: RemoteDirNotify::toRemoteURL(system:/users/emanoil/test/)
remote tdeioslave: result => KURL()
tdeio_uiserver: UIServer::totalFiles 34 0
tdeio_uiserver: UIServer::totalDirs 34 0
tdeio_uiserver: UIServer::processedDirs 34 0
tdeio_uiserver: UIServer::jobFinished id=34
Comment 5 deloptes 2017-01-30 16:26:14 CST
Created attachment 2753 [details]
bad when trash is not updated
Comment 6 deloptes 2018-04-07 17:54:27 CDT
when I kill all tdeio_trash, the icon/status is displayed correctly
Comment 7 deloptes 2018-04-07 18:07:13 CDT
so the conclusion to this is that each time tdeio: [bool TrashImpl::init()] is called, it displays the state correctly. When the tdeio_trash process is running, it does not alter the state correctly.
Comment 8 deloptes 2018-04-09 17:24:30 CDT
I narrowed it down to TrashImpl::fileAdded() when called it reads the status of .trinity/share/config/trashrc

[Status]
Empty=true

if Empty=true it should write Empty=false and sync, but either this does not happend or somehow gets rewritten. after printing the status of Empty in such case it shows "false", but in the file it is still "true" - so the update of the icon correctly represents the status of the value in the config file.

... to be continued
Comment 9 deloptes 2018-04-10 13:33:57 CDT
Created attachment 2835 [details]
A simple solution to reflect the status - the price is an overhead

isEmpty() is called in fileRemoved, while in fileAdded it first checks the status of the config file value which reports Empty=false, however in the file itself the value is Empty=true, thus it never updates the config file to reflect the state.
if we use isEmpty() in the latter case it adds an overhead to check the state, but does not relay on the status reported by m_config.readBoolEntry( "Empty", true )

regards
Comment 10 deloptes 2018-04-10 13:47:22 CDT
Created attachment 2836 [details]
A simple solution to reflect the status - the price is an overhead

cosmetic change to previous patch and 
m_config.setGroup( "Status" ); placed in the condition
Comment 11 deloptes 2018-04-10 17:18:50 CDT
Created attachment 2837 [details]
A simple solution to reflect the status - the price is an overhead

must have been working late, I missed the negation, however testing worked and I just noticed when looking at the diff
Comment 12 deloptes 2018-04-10 17:20:53 CDT
Created attachment 2838 [details]
A simple solution to reflect the status
Comment 13 Michele Calgaro 2018-04-10 20:06:06 CDT
Great job thanks Emanoil!.
Slavek or I will confirm and push it when we have the time, hopefully I can do that this Sunday.
Comment 14 deloptes 2018-04-11 01:09:40 CDT
thanks for the good word, but I am not proud of it as it does not resolve the root cause, but offers a stupid work around.

I am unable to understand why this happens - perhaps we discuss it on gmane
Comment 15 Michele Calgaro 2018-04-17 10:26:32 CDT
Emanoil, 
I have been doing some analysis on this as a temporary break-away from bug 2874. I ran into a difference of behavior in case the trash is emptied from the desktop icon popup menu or from the konqueror popup menu. This is why you see funny things with the Empty entry in trashrc. Basically there are two trash processes running, one associated to the desktop trash icon and one related to the konqueror action. Seems like that when emptying the trash from the desktop the value of the empty entry is not sync the way it should be before performing the action.
I need to spend some more time on this, probably this weekend I think.
Comment 16 deloptes 2018-04-17 13:02:30 CDT
Hi,
thanks for looking into this. I am sorry I did not mention this earlier.
Here is my test scenario

- Move the file to trash using konqueror-right click->Move to Trash
- Double click trash icon - opens konqueror
- right click on file and select restore
- Move the file to trash using konqueror-right click->Move to Trash
- icon is not updated because in trashrc it is still Empty=true, but m_config returns false in the if conditon and prevents from writing. As soon as it is written in the config I guess the notification (KDirNotify) kicks in and desktop gets updated - the icon is changed. 

This boils down to the same issue (IMO) as the original test scenario. Comment 3 was based on testing the original scenario. However the scenario mentioned above is much easier to play with.

just add a line to print m_config.readBoolEntry( "Empty" ) before the if statement and try both scenarios.

I also understood that there are too processes running for desktop and trash bin, but couldn't follow.

regards
Comment 17 Michele Calgaro 2018-04-19 10:04:19 CDT
>thanks for the good word, but I am not proud of it as it does not resolve
>the root cause, but offers a stupid work around.

Actually your patch is not a stupid work at all, it is quite good.

The problem is caused by the fact that there are different tdeio_trash processes running at the same time and all writing to the same trashrc file. Depending on the order the processes are created and the trashrc file is updated, problems could or could not arise.
Example: 
- first process is created from konqueror when trashing a file, with initially an empty trash bin. So the Empty property is initially true and after the file is trashed, Empty=false.  
- clicking on the desktop trash icon opens another konqueror, creating another trash process. Here Empty=false. Now restore the file. Empty becomes true again.
- trash another file from the original konqueror process, this will not update the trashrc value since this process already thinks the trash is not empty from the first trashed file. Result is that Empty=true but the trash bin is empty.

The above is just one of the possible situations, there are many more.

Your patch makes sure to check the real status of the trash bin when a file is added, so the status is consistent no matter how many trash processes there are and the order of their creation and operations.

In fact it is not even necessary to call isEmpty() since after adding a file to the trash bin, it will never be empty and the result of the call would be always false.
R14.1: commit f88a8e57
R14.0: commit ac79ba37

A proper solution would be to have a DCOP-based config object, then the status of the config could be shared across different processes and the updated value checked on the spot, which would prevent the problem in first place.


Could you and Q4OS team check the above commit is ok? I will wait your feedback before closing the bug.
Comment 18 Michele Calgaro 2018-04-19 10:06:48 CDT
> Result is that Empty=true but the trash bin is empty.

Meant to be:
  Result is that Empty=true but the trash bin is NOT empty.
Comment 19 deloptes 2018-04-19 11:56:56 CDT
thanks - the point checking the value of Empty is to reduce subsequent writes.
with current patch it will write to the file each time something is added to the trashbin, so my patch is not pretty clever and also suggesting that if something is added its not empty is better but still resulting in extra write.

I still think there should be a better solution
Comment 20 Michele Calgaro 2018-04-19 22:19:21 CDT
> thanks - the point checking the value of Empty is to reduce subsequent writes.
> with current patch it will write to the file each time something is added to 
> the trashbin, so my patch is not pretty clever and also suggesting that if 
> something is added its not empty is better but still resulting in extra write.
Yes, with both your patch or mine, there is a writing to the trashrc file every time a file is added. This is necessary to make sure the status of the trashbin icon is consistent, to prevent multiple tdeio_trash processes to write (or not write) the correct value. The problem comes from the fact that when a process updates the value of Emtpy, the other processes are not notified of the new value.

> I still think there should be a better solution
Yes, there is. The solution is to have a DCOP-style config object, where the value of the entries are shared across multiple processes using DCOP (or even DBUS). Then when a process accesses the Empty property, it will always read the current value (except in cases of unlikely concurrent accesses).
The point is that it would take quite a bit of time to develop something like that, and given we are already extremely short of time it may not be worth the effort. Writing to trashrc when we trash a file is not a huge overhead overall.
Moreover, using such solution would be applicable for R14.1.x onwards but not for R14.0.x because it would require an API and ABI change.
I discussed with Slavek and we agreed that for the time being the easy solution that you suggested is very good and clean and also can be backported into R14.0.x.
If in future we ever find the time to develop such DCOP-stype TDE config object,  we can revisit this bug in R14.1.x series.
Comment 21 Michele Calgaro 2018-04-24 01:40:34 CDT
Q4OS team, Emanoil, could you check if with the latest commit everything is working fine?
I will wait your feedback before closing the bug.
Comment 22 Q4OS Team 2018-04-24 04:25:47 CDT
Looks good, I am not able to reproduce it after the latest TDE-14.0.5 update. Debian 9 Stretch, TDE 14.0.5, tdebase-trinity 4:14.0.5~pre23-0debian9.0.1.+4
Comment 23 deloptes 2018-04-24 16:54:48 CDT
Thanks Michele, you can close
Comment 24 Michele Calgaro 2018-04-26 01:42:19 CDT
Great thanks.
As mentioned in one of the comments, if we ever find the time to develop a DCOP-based TDE shared config object, we shall revisit this bug.
Closing for the time being.