Not logged in. · Lost password · Register
Forum: General Help and Support Features and Functionality RSS
List locked files?
Avatar
salto #1
Member since Aug 2007 · 20 posts
Group memberships: Members
Show profile · Link to this post
Subject: List locked files?
Is there a way to retrieve a list of currently locked files to inform users?
Avatar
andi (Administrator) #2
User title: splitbrain
Member since May 2006 · 3497 posts · Location: Berlin Germany
Group memberships: Administrators, Members
Show profile · Link to this post
No but a quick find data/pages -name '*.lock' should do the trick. Writing a plugin which does this using the function from inc/search.php shouldn't be too hard as well.
Read this if you don't get any useful answers.
Lies dies wenn du keine hilfreichen Antworten bekommst.
Avatar
salto #3
Member since Aug 2007 · 20 posts
Group memberships: Members
Show profile · Link to this post
Thanks Andi, unfortunately I'm not proficient to write a plugin, but maybe someone else will, sometime.....
chi #4
Member since Jun 2006 · 1851 posts · Location: Munich Germany
Group memberships: Members, Super Mods, Wiki Managers
Show profile · Link to this post
In reply to post #2
Quote by andi:
Writing a plugin which does this using the function from inc/search.php shouldn't be too hard as well.

Hmmm, I don`t think that`s possible because search() automatically skips .lock files:

  1. 37      }elseif(substr($file,-5) == '.lock'){
  2. 38        //skip lockfiles
  3. 39        continue;
  4. 40      }

maybe this check could be removed since the lock files are in a separate directory?

Regards
chi
Please add [SOLVED] to the initial thread subject if you feel your question has been answered.
If my answer doesn't make sense maybe your question didn't either - just visit http://facepalm.org.
Avatar
andi (Administrator) #5
User title: splitbrain
Member since May 2006 · 3497 posts · Location: Berlin Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by chi:
Hmmm, I don`t think that`s possible because search() automatically skips .lock files:

Oh, hmm I think that check should be moved to the callback functions then...

Quote by chi:
maybe this check could be removed since the lock files are in a separate directory?

No, page locks are in the page directory. Only file write locks are in data/locks.
Read this if you don't get any useful answers.
Lies dies wenn du keine hilfreichen Antworten bekommst.
chi #6
Member since Jun 2006 · 1851 posts · Location: Munich Germany
Group memberships: Members, Super Mods, Wiki Managers
Show profile · Link to this post
Quote by andi:
Quote by chi:
maybe this check could be removed since the lock files are in a separate directory?
No, page locks are in the page directory. Only file write locks are in data/locks.

Ah I see, OK learned something again :-).
Please add [SOLVED] to the initial thread subject if you feel your question has been answered.
If my answer doesn't make sense maybe your question didn't either - just visit http://facepalm.org.
Avatar
Falkor #7
Member since Apr 2007 · 32 posts
Group memberships: Members
Show profile · Link to this post
Here is the code I used in an admin-plugin to list drafts. I guess you could to nearly the same thing,
just fix some of the paths if you want to list locks instead.

I'm guessing you won't need that unserialize part either...

//Falkor

    function html() {
                global $ID;

                $result = array();
                $dokupath='path/to/dokuwiki'
                $path = $dokupath.'/data/cache';

                $result = $this->findDrafts($path,$result);

                echo "<h1>Current drafts in wiki</h1>\n";

                foreach($result as $r){
                        $file=unserialize(file_get_contents($r));
                        #$file=deserialize(IO_readfile($r));

                        if(!empty($file['prefix'])){
                                $page = $file['prefix'].":".$file['id'];
                        }else{
                                $page = $file['id'];
                        }

                        echo "<h3>".$page."</h3>\n";
                        echo "<p> by user: ".$file['client']."</p>\n";
                        echo "<a href=\"".DOKU_BASE."doku.php?do=draft&id=".$page."\">Resume</a>\n";
                }
    }

        function findDrafts($dir, $result){
                $dirs = glob($dir . '/*', GLOB_ONLYDIR);

                $drafts = glob($dir . '/*.draft');

                if($drafts){
                        $result = array_merge($result, $drafts);
                }

                foreach($dirs as $d){
                        $result = $this->findDrafts($d, $result);
                }

                return $result;
        }
Avatar
Falkor #8
Member since Apr 2007 · 32 posts
Group memberships: Members
Show profile · Link to this post
I realize that I might be misunderstanding something.

What kind of locks are we talking about? I just tested by diffing the "find ./data -name '*.lock'  " result before and while editing a page in the wiki and there is a new file under ./data/lock/, but no new '.lock' files under any other directories.

//Falkor
This post was edited on 2007-08-29, 13:52 by Falkor.
chi #9
Member since Jun 2006 · 1851 posts · Location: Munich Germany
Group memberships: Members, Super Mods, Wiki Managers
Show profile · Link to this post
In reply to post #5
Quote by andi:
No, page locks are in the page directory. Only file write locks are in data/locks.

I somehow cannot verify this in the latest devel (unless I`ve overlooked something ;-)). Referring to the source the lock files are always created below data/locks/ (filename is generated via wikiLockFN() which md5sums the filename which makes the initial request for a list of lock files non-trivial IMO).

I think as pagenames are unique anyway the md5sum of the filename is not really needed?
Please add [SOLVED] to the initial thread subject if you feel your question has been answered.
If my answer doesn't make sense maybe your question didn't either - just visit http://facepalm.org.
Avatar
andi (Administrator) #10
User title: splitbrain
Member since May 2006 · 3497 posts · Location: Berlin Germany
Group memberships: Administrators, Members
Show profile · Link to this post
In reply to post #8
Quote by Falkor:
What kind of locks are we talking about? I just tested by diffing the "find ./data -name '*.lock'  " result before and while editing a page in the wiki and there is a new file under ./data/lock/, but no new '.lock' files under any other directories.

Ahh... you're right. I just had a look at the code and page lock files are no longer stored inside the page directory. They are now located inside lock directory using the md5 sum of the page id as name... which makes reverse lookup of currently locked pages not possible I fear.
Read this if you don't get any useful answers.
Lies dies wenn du keine hilfreichen Antworten bekommst.
Avatar
salto #11
Member since Aug 2007 · 20 posts
Group memberships: Members
Show profile · Link to this post
Thanks Andi, Falkor and Chi! At least now I understand why the reverse lookup is not possible. I have no idea if it is a wanted feature for more users and/or if it is a hard thing to accomplish in a future release given the fact that storage and md5 checksum of the locked files is part of the core code.
Avatar
Falkor #12
Member since Apr 2007 · 32 posts
Group memberships: Members
Show profile · Link to this post
salto, and remember - the lock usually expires after 15 min (default?) or some other short time period.
Therefore I don't think there would be a huge demand for this - I do however find the listing of drafts useful on occasion, if I have forgotten what I did last.

The reason why this works for drafts is because it stores more information, while the .lock file only stores the username that locked it, (and uses the modification time of the file, I presume).

You could try using some of the techniques from the "Maintenance"-page if you need to clean out old locks and stuff.

//Falkor
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-11-12, 05:58:59 (UTC +01:00)