INFO: How the oc_file_locks table actually works

I’m interested in understanding how to associate oc_file_locks db table entries with actual files on disk.

Can someone step me through this? I cannot figure out how to parse the github code at any level myself.

please don’t bother telling me how to clear them, that is not what I’m interested in.

==========================================================================

OK, lol…so I solved this myself. In case anyone is trying to figure out what “files” are getting placed (and remaining) into this “oc_file_locks” table, here is the technique to figure it out.

1

  1. I added a config.php entry for an undocumented flag to help. This activates log files entries for each locked file event the app performs. No need to restart your web app. Took effect for me on the fly.

'filelocking.debug' => true,

2

  1. Run the following command to force file locking, which happens for some unknown reason.

occ files:scan --all

3

  1. Review your log file to identify files being “locked”.

Example logfile snippet showing files being locked (and unlocked)

    {"reqId":"X6wuefWHMWaCfb16T2Lj","level":1,"time":"2018-03-15T21:31:54-04:00","remoteAddr":"","user":"--","app":"locking","method":"--","url":"--","message":"acquire shared lock on \"files\/Documents\/About.txt\" on storage \"home::username\"","userAgent":"--","version":"13.0.0.14"}
    {"reqId":"X6wuefWHMWaCfb16T2Lj","level":1,"time":"2018-03-15T21:31:54-04:00","remoteAddr":"","user":"--","app":"locking","method":"--","url":"--","message":"release shared lock on \"files\/Documents\/About.txt\" on storage \"home::username\"","userAgent":"--","version":"13.0.0.14"}
    {"reqId":"X6wuefWHMWaCfb16T2Lj","level":1,"time":"2018-03-15T21:31:54-04:00","remoteAddr":"","user":"--","app":"locking","method":"--","url":"--","message":"acquire shared lock on \"files\/Photos\/Hummingbird.jpg\" on storage \"home::username\"","userAgent":"--","version":"13.0.0.14"}
    {"reqId":"X6wuefWHMWaCfb16T2Lj","level":1,"time":"2018-03-15T21:31:54-04:00","remoteAddr":"","user":"--","app":"locking","method":"--","url":"--","message":"release shared lock on \"files\/Photos\/Hummingbird.jpg\" on storage \"home::username\"","userAgent":"--","version":"13.0.0.14"}

4

  1. Immediately undo the config.php entry. I recommend commenting it out as such for future reference:

// 'filelocking.debug' => true,

5

  1. Now you can create the md5 hash used in the oc_file_locks table.

Code showing md5 formula:
md5 file lock code

md5($this-getId() . '::' . trim($path, '/'))

which includes two parts - “this-getid” and “path”.

6

  1. the “path” value is the files path from here:

shared lock on \"files\/Documents\/About.txt\"

and works out to be:

files/Documents/About.txt

7

  1. “this-getid” is actually the storage location (nextcloud user path essentially)

getid is from from this portion of the log entry:

storage \"home::username\""

and works out to be simply:

home::username

8

  1. Using the formula from #5, this makes the value to be used to create the md5 hash:

home::username::files/Documents/About.txt

Note that you must create the md5 hash correctly because some techniques like echo will include hidden characters. Use an online md5 hash generator like http://www.miraclesalad.com/webtools/md5.php

md5sum = f29845c17d8cb3f75926c65294ecc88b

9

  1. Now you can confirm you can locate this md5 in the oc_file_locks table.

I used phpMyAdmin (mysql webGUI ) to search the table for a match:

Just add “files/” at the start of the md5 hash value

SELECT * FROM `oc_file_locks` WHERE `key` LIKE 'files/f29845c17d8cb3f75926c65294ecc88b' ORDER BY `id` ASC

Conclusion:

A single row should be found matching the SELECT statement. This proves the “file” is listed in the “oc_file_locks” table. Congrats, you now know how to figure out what is recorded inside this crazy table. :grin:

3 Likes

What does a value of “5” signify in the oc_file_locks table?

I have two rows where lock = 5 What does it mean?

1 Like

@deusoz
Did you figure out the meaning of “5” or higher numbers? I can’t receive an answer anywhere.