Changing how filepath is handled for Windows

This commit is contained in:
2018-01-20 17:16:13 -05:00
parent c87443ca40
commit 83a03b3ef6
7 changed files with 69 additions and 39 deletions

View File

@@ -4,10 +4,11 @@
ServerPort = ":8000" #leave format as is it expects a string with colon ServerPort = ":8000" #leave format as is it expects a string with colon
ServerAddr = "" #blank will bind to default IP address, usually fine to leave be ServerAddr = "" #blank will bind to default IP address, usually fine to leave be
LogLevel = "Warn" # Options = Debug, Info, Warn, Error, Fatal, Panic LogLevel = "Warn" # Options = Debug, Info, Warn, Error, Fatal, Panic
LogOutput = "file" #Options = file, stdout #file will print it to logs/server.log LogOutput = "stdout" #Options = file, stdout #file will print it to logs/server.log
SeedRatioStop = 1.50 #automatically stops the torrent after it reaches this seeding ratio SeedRatioStop = 1.50 #automatically stops the torrent after it reaches this seeding ratio
DefaultMoveFolder = "downloaded" #default path that a finished torrent is symlinked to after completion. Torrents added via RSS will default here #Relative or absolute path accepted, the server will convert any relative path to an absolute path.
DefaultMoveFolder = 'downloaded' #default path that a finished torrent is symlinked to after completion. Torrents added via RSS will default here
[notifications] [notifications]
@@ -23,14 +24,14 @@
[torrentClientConfig] [torrentClientConfig]
DownloadDir = "downloading" #the full OR relative path where the torrent server stores in-progress torrents DownloadDir = 'downloading' #the full OR relative path where the torrent server stores in-progress torrents
Seed = true #boolean #seed after download Seed = true #boolean #seed after download
# Never send chunks to peers. # Never send chunks to peers.
NoUpload = false #boolean NoUpload = false #boolean
#The address to listen for new uTP and TCP bittorrent protocolconnections. DHT shares a UDP socket with uTP unless configured otherwise. #The address to listen for new uTP and TCP bittorrent protocol connections. DHT shares a UDP socket with uTP unless configured otherwise.
ListenAddr = "" #Leave Blank for default, syntax "HOST:PORT" ListenAddr = "" #Leave Blank for default, syntax "HOST:PORT"
#Don't announce to trackers. This only leaves DHT to discover peers. #Don't announce to trackers. This only leaves DHT to discover peers.
@@ -88,7 +89,7 @@
# Don't respond to queries from other nodes. # Don't respond to queries from other nodes.
Passive = false # boolean Passive = false # boolean
# the default addressses are "router.utorrent.com:6881","router.bittorrent.com:6881","dht.transmissionbt.com:6881","dht.aelitis.com:6881", # the default addresses are "router.utorrent.com:6881","router.bittorrent.com:6881","dht.transmissionbt.com:6881","dht.aelitis.com:6881",
#https:#github.com/anacrolix/dht/blob/master/dht.go #https:#github.com/anacrolix/dht/blob/master/dht.go
StartingNodes = "dht.GlobalBootstrapAddrs" StartingNodes = "dht.GlobalBootstrapAddrs"
@@ -108,5 +109,5 @@
#Called when a peer successfully announces to us. #Called when a peer successfully announces to us.
OnAnnouncePeer = "func(infoHash metainfo.Hash, peer Peer)" OnAnnouncePeer = "func(infoHash metainfo.Hash, peer Peer)"
#How long to wait before resending queries that haven't received a response. Defaults to a random value between 4.5 and 5.5s. #How long to wait before re-sending queries that haven't received a response. Defaults to a random value between 4.5 and 5.5s.
QueryResendDelay = "func() time.Duration" QueryResendDelay = "func() time.Duration"

View File

@@ -107,7 +107,10 @@ func readTorrentFileFromDB(element *Storage.TorrentLocal, tclient *torrent.Clien
//StartTorrent creates the storage.db entry and starts A NEW TORRENT and adds to the running torrent array //StartTorrent creates the storage.db entry and starts A NEW TORRENT and adds to the running torrent array
func StartTorrent(clientTorrent *torrent.Torrent, torrentLocalStorage Storage.TorrentLocal, torrentDbStorage *storm.DB, dataDir string, torrentType string, torrentFileName string, torrentStoragePath string) { func StartTorrent(clientTorrent *torrent.Torrent, torrentLocalStorage Storage.TorrentLocal, torrentDbStorage *storm.DB, dataDir string, torrentType string, torrentFileName string, torrentStoragePath string) {
timeOutInfo(clientTorrent, 45) //seeing if adding the torrrent times out (giving 45 seconds) timedOut := timeOutInfo(clientTorrent, 45) //seeing if adding the torrrent times out (giving 45 seconds)
if timedOut { //if we fail to add the torrent return
return
}
var TempHash metainfo.Hash var TempHash metainfo.Hash
TempHash = clientTorrent.InfoHash() TempHash = clientTorrent.InfoHash()
allStoredTorrents := Storage.FetchAllStoredTorrents(torrentDbStorage) allStoredTorrents := Storage.FetchAllStoredTorrents(torrentDbStorage)
@@ -132,7 +135,7 @@ func StartTorrent(clientTorrent *torrent.Torrent, torrentLocalStorage Storage.To
} }
torrentLocalStorage.TorrentFile = torrentfile //storing the entire file in to database 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") Logger.WithFields(logrus.Fields{"Storage Path": torrentStoragePath, "Torrent Name": clientTorrent.Name()}).Info("Adding Torrent with following storage path")
torrentFiles := clientTorrent.Files() //storing all of the files in the database along with the priority torrentFiles := clientTorrent.Files() //storing all of the files in the database along with the priority
var TorrentFilePriorityArray = []Storage.TorrentFilePriority{} var TorrentFilePriorityArray = []Storage.TorrentFilePriority{}
for _, singleFile := range torrentFiles { //creating the database setup for the file array for _, singleFile := range torrentFiles { //creating the database setup for the file array

View File

@@ -2,15 +2,13 @@ package engine
import ( import (
"fmt" "fmt"
"path/filepath"
"github.com/sirupsen/logrus"
"golang.org/x/time/rate"
"github.com/anacrolix/dht" "github.com/anacrolix/dht"
"github.com/anacrolix/torrent" "github.com/anacrolix/torrent"
"github.com/sirupsen/logrus"
"github.com/spf13/viper" "github.com/spf13/viper"
"golang.org/x/time/rate"
) )
//FullClientSettings contains all of the settings for our entire application //FullClientSettings contains all of the settings for our entire application
@@ -31,7 +29,7 @@ func defaultConfig() FullClientSettings {
var Config FullClientSettings var Config FullClientSettings
Config.Version = 1.0 Config.Version = 1.0
Config.LoggingLevel = 3 //Warn level Config.LoggingLevel = 3 //Warn level
Config.TorrentConfig.DataDir = "downloads" //the full OR relative path of the default download directory for torrents Config.TorrentConfig.DataDir = "downloads" //the absolute or relative path of the default download directory for torrents
Config.TFileUploadFolder = "uploadedTorrents" Config.TFileUploadFolder = "uploadedTorrents"
Config.TorrentConfig.Seed = true Config.TorrentConfig.Seed = true
Config.HTTPAddr = ":8000" Config.HTTPAddr = ":8000"
@@ -68,9 +66,18 @@ func FullClientSettingsNew() FullClientSettings {
seedRatioStop := viper.GetFloat64("serverConfig.SeedRatioStop") seedRatioStop := viper.GetFloat64("serverConfig.SeedRatioStop")
httpAddr = httpAddrIP + httpAddrPort httpAddr = httpAddrIP + httpAddrPort
pushBulletToken := viper.GetString("notifications.PushBulletToken") pushBulletToken := viper.GetString("notifications.PushBulletToken")
defaultMoveFolder := viper.GetString("serverConfig.DefaultMoveFolder") defaultMoveFolder := filepath.ToSlash(viper.GetString("serverConfig.DefaultMoveFolder")) //Converting the string literal into a filepath
defaultMoveFolderAbs, err := filepath.Abs(defaultMoveFolder)
if err != nil {
fmt.Println("Failed creating absolute path for defaultMoveFolder", err)
}
dataDir := filepath.ToSlash(viper.GetString("torrentClientConfig.DownloadDir")) //Converting the string literal into a filepath
dataDirAbs, err := filepath.Abs(dataDir) //Converting to an absolute file path
if err != nil {
fmt.Println("Failed creating absolute path for dataDir", err)
}
dataDir := viper.GetString("torrentClientConfig.DownloadDir")
listenAddr := viper.GetString("torrentClientConfig.ListenAddr") listenAddr := viper.GetString("torrentClientConfig.ListenAddr")
disablePex := viper.GetBool("torrentClientConfig.DisablePEX") disablePex := viper.GetBool("torrentClientConfig.DisablePEX")
noDHT := viper.GetBool("torrentClientConfig.NoDHT") noDHT := viper.GetBool("torrentClientConfig.NoDHT")
@@ -124,7 +131,7 @@ func FullClientSettingsNew() FullClientSettings {
} }
tConfig := torrent.Config{ tConfig := torrent.Config{
DataDir: dataDir, DataDir: dataDirAbs,
ListenAddr: listenAddr, ListenAddr: listenAddr,
DisablePEX: disablePex, DisablePEX: disablePex,
NoDHT: noDHT, NoDHT: noDHT,
@@ -149,7 +156,7 @@ func FullClientSettingsNew() FullClientSettings {
TorrentConfig: tConfig, TorrentConfig: tConfig,
TFileUploadFolder: "uploadedTorrents", TFileUploadFolder: "uploadedTorrents",
PushBulletToken: pushBulletToken, PushBulletToken: pushBulletToken,
DefaultMoveFolder: defaultMoveFolder, DefaultMoveFolder: defaultMoveFolderAbs,
} }
return Config return Config

View File

@@ -44,7 +44,7 @@ export default class addTorrentFilePopup extends React.Component {
open: false, open: false,
torrentFileName: "", torrentFileName: "",
torrentFileValue: [], torrentFileValue: [],
storageValue: "", storageValue: ``, //raw string for possible windows filepath
showDrop: true, showDrop: true,
}; };
@@ -74,7 +74,7 @@ export default class addTorrentFilePopup extends React.Component {
} }
console.log("Sending magnet link: ", torrentFileMessage); console.log("Sending magnet link: ", torrentFileMessage);
ws.send(JSON.stringify(torrentFileMessage)); ws.send(JSON.stringify(torrentFileMessage));
this.setState({torrentFileName: "", storageValue: "", torrentFileValue: [], showDrop: true}) this.setState({torrentFileName: "", storageValue: ``, torrentFileValue: [], showDrop: true})
} }
} }

View File

@@ -36,7 +36,7 @@ export default class addTorrentPopup extends React.Component {
state = { state = {
open: false, open: false,
magnetLinkValue: "", magnetLinkValue: "",
storageValue: "", storageValue: ``,
}; };

49
main.go
View File

@@ -60,21 +60,22 @@ func main() {
Storage.Logger = Logger Storage.Logger = Logger
Config := Engine.FullClientSettingsNew() //grabbing from settings.go Config := Engine.FullClientSettingsNew() //grabbing from settings.go
if Config.LoggingOutput == "file" { if Config.LoggingOutput == "file" {
_, err := os.Stat("logs/server.log") _, err := os.Stat("logs")
if os.IsNotExist(err) { if os.IsNotExist(err) {
err := os.Mkdir("logs", 0755) err := os.Mkdir("logs", 0755)
if err != nil { if err != nil {
fmt.Println("Unable to create 'log' folder for logging.... please check permissions.. forcing output to stdout") fmt.Println("Unable to create 'log' folder for logging.... please check permissions.. forcing output to stdout", err)
}
} 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, 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")
Logger.Out = os.Stdout Logger.Out = os.Stdout
} 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, 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")
Logger.Out = os.Stdout
}
Logger.Out = file
} }
Logger.Out = file
} }
} else { } else {
Logger.Out = os.Stdout Logger.Out = os.Stdout
@@ -107,9 +108,9 @@ func main() {
TorrentLocalArray = Storage.FetchAllStoredTorrents(db) //pulling in all the already added torrents TorrentLocalArray = Storage.FetchAllStoredTorrents(db) //pulling in all the already added torrents
if TorrentLocalArray != nil { //the first creation of the running torrent array //since we are adding all of them in we use a coroutine... just allows the web ui to load then it will load in the torrents if TorrentLocalArray != nil { //the first creation of the running torrent array //since we are adding all of them in we use a coroutine... just allows the web ui to load then it will load in the torrents
//go func() { //TODO instead of running all torrent fetches in coroutine see if possible to run each single one in a routine so we don't wait for ALL of them to be verified go func() { //TODO instead of running all torrent fetches in coroutine see if possible to run each single one in a routine so we don't wait for ALL of them to be verified
RunningTorrentArray = Engine.CreateRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db) RunningTorrentArray = Engine.CreateRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db)
//}() }()
} else { } else {
Logger.Info("Database is empty, no torrents loaded") Logger.Info("Database is empty, no torrents loaded")
} }
@@ -240,7 +241,16 @@ func main() {
case "magnetLinkSubmit": //if we detect a magnet link we will be adding a magnet torrent case "magnetLinkSubmit": //if we detect a magnet link we will be adding a magnet torrent
storageValue := msg.MessageDetail storageValue := msg.MessageDetail
if storageValue == "" { if storageValue == "" {
storageValue = Config.DefaultMoveFolder storageValue, err = filepath.Abs(filepath.ToSlash(Config.DefaultMoveFolder))
if err != nil {
Logger.WithFields(logrus.Fields{"err": err, "MagnetLink": Config.DefaultMoveFolder}).Error("Unable to add Storage Path")
}
} else {
storageValue, err = filepath.Abs(filepath.ToSlash(storageValue))
if err != nil {
Logger.WithFields(logrus.Fields{"err": err, "MagnetLink": storageValue}).Error("Unable to add Storage Path")
storageValue, _ = filepath.Abs(filepath.ToSlash(Config.DefaultMoveFolder))
}
} }
for _, magnetLink := range msg.Payload { for _, magnetLink := range msg.Payload {
clientTorrent, err := tclient.AddMagnet(magnetLink) //reading the payload into the torrent client clientTorrent, err := tclient.AddMagnet(magnetLink) //reading the payload into the torrent client
@@ -262,7 +272,16 @@ func main() {
FileName := msg.MessageDetail FileName := msg.MessageDetail
storageValue := msg.MessageDetailTwo storageValue := msg.MessageDetailTwo
if storageValue == "" { if storageValue == "" {
storageValue = Config.DefaultMoveFolder storageValue, err = filepath.Abs(filepath.ToSlash(Config.DefaultMoveFolder))
if err != nil {
Logger.WithFields(logrus.Fields{"err": err, "MagnetLink": Config.DefaultMoveFolder}).Error("Unable to add Storage Path")
}
} else {
storageValue, err = filepath.Abs(filepath.ToSlash(storageValue))
if err != nil {
Logger.WithFields(logrus.Fields{"err": err, "MagnetLink": storageValue}).Error("Unable to add Storage Path")
storageValue, _ = filepath.Abs(filepath.ToSlash(Config.DefaultMoveFolder))
}
} }
filePath := filepath.Join(Config.TFileUploadFolder, FileName) //creating a full filepath to store the .torrent files filePath := filepath.Join(Config.TFileUploadFolder, FileName) //creating a full filepath to store the .torrent files

View File

@@ -85237,7 +85237,7 @@ var addTorrentPopup = function (_React$Component) {
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = addTorrentPopup.__proto__ || Object.getPrototypeOf(addTorrentPopup)).call.apply(_ref, [this].concat(args))), _this), _this.state = { return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = addTorrentPopup.__proto__ || Object.getPrototypeOf(addTorrentPopup)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
open: false, open: false,
magnetLinkValue: "", magnetLinkValue: "",
storageValue: "" storageValue: ''
}, _this.handleClickOpen = function () { }, _this.handleClickOpen = function () {
_this.setState({ open: true }); _this.setState({ open: true });
@@ -93502,7 +93502,7 @@ var addTorrentFilePopup = function (_React$Component) {
open: false, open: false,
torrentFileName: "", torrentFileName: "",
torrentFileValue: [], torrentFileValue: [],
storageValue: "", storageValue: '', //raw string for possible windows filepath
showDrop: true showDrop: true
}, _this.handleClickOpen = function () { }, _this.handleClickOpen = function () {
_this.setState({ open: true }); _this.setState({ open: true });
@@ -93526,7 +93526,7 @@ var addTorrentFilePopup = function (_React$Component) {
}; };
console.log("Sending magnet link: ", torrentFileMessage); console.log("Sending magnet link: ", torrentFileMessage);
ws.send(JSON.stringify(torrentFileMessage)); ws.send(JSON.stringify(torrentFileMessage));
_this.setState({ torrentFileName: "", storageValue: "", torrentFileValue: [], showDrop: true }); _this.setState({ torrentFileName: "", storageValue: '', torrentFileValue: [], showDrop: true });
}; };
}, _this.onFileLoad = function (file) { }, _this.onFileLoad = function (file) {
_this.setState({ torrentFileName: file[0].name }); _this.setState({ torrentFileName: file[0].name });