Use fsnotify to refresh hgweb

Review Request #2412 — Created March 31, 2023 and discarded

Information

grim/hgkeeper
default

Reviewers

If a repository got renamed or removed hgweb was not updated and
show the old repository in the index. Also the new repo path
was not added.

So let's add a watcher to refreshes it immediately.


 
Summary ID Author
Use fsnotify to refresh hgweb
If a repository got renamed or removed hgweb was not updated and show the old repository in the index. Also the new repo path was not added. So let's add a watcher to refreshes it immediately. This fixes HGKEEPER-25.
71af3d389d47d07a461a85b61456ed8adb2cb465 Andre Klitzing
Description From Last Updated

I will try something else... so lets wait here. :-)

aklitzing@gmail.comaklitzing@gmail.com

you can drop waitForEvent and just use a break on line 24.

grimgrim

This code assumes that the go routine for previous watcher has finished. I'm not very familar with the fsnotify package, …

grimgrim

Maybe we should add the parent directory only if not already watched. Otherwise we will watch all content in that …

aklitzing@gmail.comaklitzing@gmail.com
aklitzing@gmail.com
aklitzing@gmail.com
aklitzing@gmail.com
  1. 
      
  2. access/access.go

    func Refresh() error {
        accessLock.Lock()
        defer accessLock.Unlock()
    

    Is it necessary to lock that, too? Don't know... how to lock that?

  3. 
      
aklitzing@gmail.com
aklitzing@gmail.com
  1. 
      
  2. ssh/commands/serve.go

        if s.repoName == access.AdminRepo() {
            zap.S().Info("admin repo updated, refreshing access control")
    
            return access.Refresh()
        }
    

    Maybe this can be "removed" as fsnotify retriggers automatically the Refresh now.

    1. Mh, Maybe not... sub-directories are not watched.

  3. 
      
aklitzing@gmail.com
aklitzing@gmail.com
  1. 
      
  2. access/hgweb.go (Diff revision 4)
     
     
     
     

    Maybe we should add the parent directory only if not already watched. Otherwise we will watch all content in that directory, too. That would be nice in hgkeeper working directory. But Refresh() hgkeeper repo stuff if another repository has an updated working-directory is strange.

    Maybe you want to change this a little bit. :-)

    1. I will re-write a little bit. Would help if you could merge the logging stuff before. :-)

    2. There's a conflict on the merging stuff right now. If you can rebase that commit onto default and update the review request I will be able to merge it.

  3. 
      
grim
grim
  1. 
      
  2. access/hgweb.go (Diff revision 4)
     
     

    you can drop waitForEvent and just use a break on line 24.

  3. access/hgweb.go (Diff revision 4)
     
     

    This code assumes that the go routine for previous watcher has finished. I'm not very familar with the fsnotify package, but I'm also worried we're going to trigger this a lot.

    For example, a push to the admin repo is going create multiple file system events, which, if I'm not mistaken, is going to run the refresh multiple times when it really just needs to be once during that push.

    Maybe we need to cancel the fsnotify.Watcher while we're getting an admin repo update?

    That wouldn't cover the case where someone renames a repository and a bunch of files change though. So maybe we need a way to manually add stop and create the watcher, so that we can better control it.

    For example, during admin repo push, stop the watcher, handle the push, and then access.Refresh and tell it to create the fsnotify.Watcher.

    Likewise, the fsnotify.Watcher should ignore additional events for some duration of time, or not create itself until the queue of events is gone?

    Actually do we need to recreate this each time? If we can just have a single instance and tell it to ignore events for a bit, that seems like the best case.

    1. The go routine should exit itself on a "valid event". So we close the Watcher in line 31 and there will be no more event handling after ONE "valid event".
      I reduced it to "RENAME and REMOVE" only. CHMOD and WRITE is useless. CREATE is a littbe bit complicated it we want to watch "empty" directories. As it is possible with "hg init ssh://" we could ignore this at the moment.

      It will watch parent directories only. So it won't update if something got changed in admin repository anymore. A refresh of hgweb should be enough for this and the mutex is easier to avoid race condition with the go routine.

      I didn't tested it well at the moment. I will sleep a night about it. :-)

    2. oh, yes. After a push we need to cancel running goroutine.... I will look into it later.

  4. 
      
aklitzing@gmail.com
aklitzing@gmail.com
aklitzing@gmail.com
aklitzing@gmail.com
  1. 
      
  2. I will try something else... so lets wait here. :-)

    1. /r/2421/ this could be an alternative.

  3. 
      
aklitzing@gmail.com
Review request changed

Status: Discarded

Loading...