mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-27 23:07:14 -05:00
Move downloads dir validation into Common
This commit is contained in:
parent
a787a5af1e
commit
c23ab77a58
@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
import os, sys, time, argparse, threading
|
import os, sys, time, argparse, threading
|
||||||
|
|
||||||
from . import strings
|
from . import strings
|
||||||
from .common import Common
|
from .common import Common, DownloadsDirErrorCannotCreate, DownloadsDirErrorNotWritable
|
||||||
from .web import Web
|
from .web import Web
|
||||||
from .onion import *
|
from .onion import *
|
||||||
from .onionshare import OnionShare
|
from .onionshare import OnionShare
|
||||||
@ -92,17 +92,19 @@ def main(cwd=None):
|
|||||||
# In receive mode, validate downloads dir
|
# In receive mode, validate downloads dir
|
||||||
if receive:
|
if receive:
|
||||||
valid = True
|
valid = True
|
||||||
if not os.path.isdir(common.settings.get('downloads_dir')):
|
try:
|
||||||
try:
|
common.validate_downloads_dir()
|
||||||
os.mkdir(common.settings.get('downloads_dir'), 0o700)
|
|
||||||
except:
|
except DownloadsDirErrorCannotCreate:
|
||||||
print(strings._('error_cannot_create_downloads_dir').format(common.settings.get('downloads_dir')))
|
print(strings._('error_cannot_create_downloads_dir').format(common.settings.get('downloads_dir')))
|
||||||
valid = False
|
valid = False
|
||||||
if valid and not os.access(common.settings.get('downloads_dir'), os.W_OK):
|
|
||||||
|
except DownloadsDirErrorNotWritable:
|
||||||
print(strings._('error_downloads_dir_not_writable').format(common.settings.get('downloads_dir')))
|
print(strings._('error_downloads_dir_not_writable').format(common.settings.get('downloads_dir')))
|
||||||
valid = False
|
valid = False
|
||||||
if not valid:
|
|
||||||
sys.exit()
|
if not valid:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
# Create the Web object
|
# Create the Web object
|
||||||
web = Web(common, False, receive)
|
web = Web(common, False, receive)
|
||||||
|
@ -31,6 +31,21 @@ import time
|
|||||||
|
|
||||||
from .settings import Settings
|
from .settings import Settings
|
||||||
|
|
||||||
|
|
||||||
|
class DownloadsDirErrorCannotCreate(Exception):
|
||||||
|
"""
|
||||||
|
Error creating the downloads dir (~/OnionShare by default).
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DownloadsDirErrorNotWritable(Exception):
|
||||||
|
"""
|
||||||
|
Downloads dir is not writable.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Common(object):
|
class Common(object):
|
||||||
"""
|
"""
|
||||||
The Common object is shared amongst all parts of OnionShare.
|
The Common object is shared amongst all parts of OnionShare.
|
||||||
@ -321,6 +336,19 @@ class Common(object):
|
|||||||
}"""
|
}"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def validate_downloads_dir(self):
|
||||||
|
"""
|
||||||
|
Validate that downloads_dir exists, and create it if it doesn't
|
||||||
|
"""
|
||||||
|
if not os.path.isdir(self.settings.get('downloads_dir')):
|
||||||
|
try:
|
||||||
|
os.mkdir(self.settings.get('downloads_dir'), 0o700)
|
||||||
|
except:
|
||||||
|
raise DownloadsDirErrorCannotCreate
|
||||||
|
|
||||||
|
if not os.access(self.settings.get('downloads_dir'), os.W_OK):
|
||||||
|
raise DownloadsDirErrorNotWritable
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def random_string(num_bytes, output_len=None):
|
def random_string(num_bytes, output_len=None):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user