Skip to content

Commit

Permalink
Close files, closes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
probonopd committed Nov 3, 2019
1 parent 18080fa commit 3a4cf0a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/appimaged/appimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ func saveToPngFile(filePath string, m image.Image) error {
func (ai AppImage) determineImageType() int {
log.Println(ai.path)
f, err := os.Open(ai.path)
defer f.Close()

// printError("appimage", err)
if err != nil {
return -1 // If we were not able to open the file, then we report that it is not an AppImage
Expand All @@ -330,7 +332,6 @@ func (ai AppImage) determineImageType() int {
return 1
}

f.Close()
return -1
}

Expand Down Expand Up @@ -445,6 +446,7 @@ func (ai AppImage) integrateOrUnintegrate() {

func ioReader(file string) io.ReaderAt {
r, err := os.Open(file)
defer r.Close()
printError("appimage: elf:", err)
return r
}
Expand Down
7 changes: 7 additions & 0 deletions src/appimaged/inotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ package main
// Super block root watch is designed to solve the scalability issues with inotify recursive watches.
// The fanotify super block watch patch set is meant to fill this gap in functionality and add the functionality of a root watch.
// It was merged to kernel v5.1-rc1.
//
// We should find a way to do with inotify since
// normal users can only have 128 watched directories
// (subdirectories seemingly count separately)
// me@host:~$ cat /proc/sys/fs/inotify/max_user_instances
// 128

import (
"log"
Expand All @@ -18,6 +24,7 @@ import (
// and how would this improve performance?

func inotifyWatch(path string) {

watcher, err := recwatch.NewRecWatcher(path, true)
printError("inotify, probably already watching", err)
defer watcher.Close()
Expand Down
17 changes: 16 additions & 1 deletion src/appimaged/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ func main() {
// Periodically move desktop files from their temporary location
// into the menu, so that the menu does not get rebuilt all the time
func moveDesktopFiles() {
// log.Println("main: Ticktock")
// log.Println("main: xxxxxxxxxxxxxxx Ticktock")

// log.Println(watchedDirectories)
// for _, w := range watchedDirectories {
// log.Println(w.Path)
// }

for _, path := range toBeIntegrated {
ai := newAppImage(path)
Expand Down Expand Up @@ -170,6 +175,16 @@ func printError(context string, e error) {

func watchDirectories() {

// Unwatch everything we were watching before,
// prevent from trying to watch the same multiple times
// Results in:
// panic: close of closed channel
// for _, w := range watchedDirectories {
// log.Println("stop watching", w.Path)
// w.Close()
// }
// watchedDirectories = nil

// Register AppImages from well-known locations
// https://github.com/AppImage/appimaged#monitored-directories
home, _ := os.UserHomeDir()
Expand Down
2 changes: 1 addition & 1 deletion src/appimaged/prerequisites.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func checkToolAvailable(toolname string) bool {
func stopSystemdService(servicename string) {
cmd := exec.Command("systemctl", "--user", "stop", servicename+".service")
if err := cmd.Run(); err != nil {
printError(cmd.String(), err)
printError(cmd.String(), err) // Needs Go 1.13
} else {
*cleanPtr = true // Clean up pre-existing desktop files from the other AppImage system integration daemon
}
Expand Down

0 comments on commit 3a4cf0a

Please sign in to comment.