From c87443ca40b714c69cf072eaba9162f4638e31f1 Mon Sep 17 00:00:00 2001 From: deranjer Date: Sat, 20 Jan 2018 11:26:46 -0500 Subject: [PATCH] Adding more logging options, changing file permissions on move torrent --- engine/doneTorrentActions.go | 7 ++++++- engine/engine.go | 5 +++-- main.go | 7 ++++++- storage/storage.go | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/engine/doneTorrentActions.go b/engine/doneTorrentActions.go index 378a06d4..6da57ff6 100644 --- a/engine/doneTorrentActions.go +++ b/engine/doneTorrentActions.go @@ -17,7 +17,7 @@ import ( //MoveAndLeaveSymlink takes the file from the default download dir and moves it to the user specified directory and then leaves a symlink behind. func MoveAndLeaveSymlink(config FullClientSettings, singleTorrent *torrent.Torrent, db *storm.DB) { - Logger.WithFields(logrus.Fields{"Torrent Name": singleTorrent.Name()}).Error("Move and Create symlink started for torrent") + Logger.WithFields(logrus.Fields{"Torrent Name": singleTorrent.Name()}).Info("Move and Create symlink started for torrent") tStorage := Storage.FetchTorrentFromStorage(db, singleTorrent.InfoHash().String()) oldFilePath := filepath.Join(config.TorrentConfig.DataDir, singleTorrent.Name()) newFilePath := filepath.Join(tStorage.StoragePath, singleTorrent.Name()) @@ -39,6 +39,7 @@ func MoveAndLeaveSymlink(config FullClientSettings, singleTorrent *torrent.Torre if oldFileInfo.IsDir() { os.Mkdir(newFilePath, 0755) folderCopy.Copy(oldFilePath, newFilePath) //copy the folder to the new location + os.Chmod(newFilePath, 0777) notifyUser(tStorage, config, singleTorrent, db) return } @@ -68,6 +69,7 @@ func MoveAndLeaveSymlink(config FullClientSettings, singleTorrent *torrent.Torre notifyUser(tStorage, config, singleTorrent, db) } else { folderCopy.Copy(oldFilePath, newFilePath) + os.Chmod(newFilePath, 0777) //changing permissions on the new file to be permissive os.RemoveAll(oldFilePath) err := os.Symlink(newFilePath, oldFilePath) //For all other OS's create a symlink if err != nil { @@ -82,6 +84,7 @@ func MoveAndLeaveSymlink(config FullClientSettings, singleTorrent *torrent.Torre } func notifyUser(tStorage Storage.TorrentLocal, config FullClientSettings, singleTorrent *torrent.Torrent, db *storm.DB) { + Logger.WithFields(logrus.Fields{"New File Path": tStorage.StoragePath, "Torrent Name": singleTorrent.Name()}).Info("Attempting to notify user..") tStorage.TorrentMoved = true Storage.AddTorrentLocalStorage(db, tStorage) //Updating the fact that we moved the torrent if config.PushBulletToken != "" { @@ -94,5 +97,7 @@ func notifyUser(tStorage Storage.TorrentLocal, config FullClientSettings, single return } Logger.WithFields(logrus.Fields{"Torrent": singleTorrent.Name(), "New File Path": tStorage.StoragePath}).Info("Pushbullet note sent") + } else { + Logger.WithFields(logrus.Fields{"New File Path": tStorage.StoragePath, "Torrent Name": singleTorrent.Name()}).Info("No pushbullet API key set, not notifying") } } diff --git a/engine/engine.go b/engine/engine.go index 78a62d35..9e8b712d 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -61,7 +61,7 @@ func ForceRSSRefresh(db *storm.DB, RSSFeedStore Storage.RSSFeedStore) { //Todo.. //timeOutInfo forcing a timeout of the torrent if it doesn't load from program restart func timeOutInfo(clientTorrent *torrent.Torrent, seconds time.Duration) (deleted bool) { - Logger.WithFields(logrus.Fields{"torrentName": clientTorrent.Name()}).Info("Attempting to download info for torrent") + Logger.WithFields(logrus.Fields{"Seconds to wait for info...": seconds}).Info("Attempting to download info for torrent") timeout := make(chan bool, 1) //creating a timeout channel for our gotinfo go func() { time.Sleep(seconds * time.Second) @@ -85,7 +85,7 @@ func readTorrentFileFromDB(element *Storage.TorrentLocal, tclient *torrent.Clien if err != nil { Logger.WithFields(logrus.Fields{"tempfile": tempFile, "err": err}).Error("Unable to create tempfile") } - defer tempFile.Close() //Todo.. if we remove this do we need to close it? + //defer tempFile.Close() //Todo.. if we remove this do we need to close it? defer os.Remove(tempFile.Name()) if _, err := tempFile.Write(element.TorrentFile); err != nil { //writing out out the entire file back into the temp dir from boltdb Logger.WithFields(logrus.Fields{"tempfile": tempFile, "err": err}).Error("Unable to write to tempfile") @@ -132,6 +132,7 @@ func StartTorrent(clientTorrent *torrent.Torrent, torrentLocalStorage Storage.To } torrentLocalStorage.TorrentFile = torrentfile //storing the entire file in to database } + Logger.WithFields(logrus.Fields{"Storage Path": torrentStoragePath, "Torrent Name": clientTorrent.Name()}).Error("Adding Torrent with following storage path") torrentFiles := clientTorrent.Files() //storing all of the files in the database along with the priority var TorrentFilePriorityArray = []Storage.TorrentFilePriority{} for _, singleFile := range torrentFiles { //creating the database setup for the file array diff --git a/main.go b/main.go index 32b687db..5d32dae4 100644 --- a/main.go +++ b/main.go @@ -68,7 +68,7 @@ func main() { } } else { os.Remove("logs/server.log") //cleanup the old log on every restart - file, err := os.OpenFile("logs/server.log", os.O_CREATE|os.O_WRONLY, 0666) //creating the log file + file, err := os.OpenFile("logs/server.log", os.O_CREATE|os.O_WRONLY, 0755) //creating the log file defer file.Close() //TODO.. since we write to this constantly how does close work? if err != nil { fmt.Println("Unable to create file for logging.... please check permissions.. forcing output to stdout") @@ -239,6 +239,9 @@ func main() { case "magnetLinkSubmit": //if we detect a magnet link we will be adding a magnet torrent storageValue := msg.MessageDetail + if storageValue == "" { + storageValue = Config.DefaultMoveFolder + } for _, magnetLink := range msg.Payload { clientTorrent, err := tclient.AddMagnet(magnetLink) //reading the payload into the torrent client if err != nil { @@ -400,5 +403,7 @@ func main() { }) if err := http.ListenAndServe(httpAddr, nil); err != nil { Logger.WithFields(logrus.Fields{"error": err}).Fatal("Unable to listen on the http Server!") + } else { + fmt.Println("Server started on:", httpAddr) } } diff --git a/storage/storage.go b/storage/storage.go index d5a61e16..ad0b7a69 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -76,7 +76,7 @@ func FetchAllStoredTorrents(torrentStorage *storm.DB) (torrentLocalArray []*Torr //AddTorrentLocalStorage is called when adding a new torrent via any method, requires the boltdb pointer and the torrentlocal struct func AddTorrentLocalStorage(torrentStorage *storm.DB, local TorrentLocal) { - Logger.WithFields(logrus.Fields{"database": torrentStorage, "Torrent": local.TorrentName, "File(if file)": local.TorrentFileName}).Info("Adding new Torrent to database") + Logger.WithFields(logrus.Fields{"Storage Path": local.StoragePath, "Torrent": local.TorrentName, "File(if file)": local.TorrentFileName}).Info("Adding new Torrent to database") err := torrentStorage.Save(&local) if err != nil { Logger.WithFields(logrus.Fields{"database": torrentStorage, "error": err}).Error("Error adding new Torrent to database!") @@ -115,7 +115,7 @@ func DelTorrentLocalStorageAndFiles(torrentStorage *storm.DB, selectedHash strin if err != nil { Logger.WithFields(logrus.Fields{"singleTorrent": singleTorrentInfo, "error": err}).Error("Error deleting torrent struct!") } else { - Logger.WithFields(logrus.Fields{"singleTorrent": singleTorrentInfo.TorrentName}).Error("Deleted Torrent Struct") + Logger.WithFields(logrus.Fields{"singleTorrent": singleTorrentInfo.TorrentName}).Info("Deleted Torrent Struct") } }