Skip to content

Commit

Permalink
Merge pull request uunicorn#158 from mattgia/fix-empty-data-dir
Browse files Browse the repository at this point in the history
Fix issue where /var/lib/python-validity doesn't exist on daemon startup
  • Loading branch information
uunicorn authored May 8, 2023
2 parents c7a3ccb + 50566b8 commit ca21528
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bin/validity-sensors-firmware
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import urllib.request

from usb import core as usb_core

from validitysensor.init_data_dir import PYTHON_VALIDITY_DATA_DIR
from validitysensor.firmware_tables import FIRMWARE_NAMES, FIRMWARE_URIS
from validitysensor.usb import SupportedDevices

python_validity_data = '/var/run/python-validity/'


def download_and_extract_fw(dev_type, fwdir, fwuri=None):
Expand Down Expand Up @@ -99,4 +99,4 @@ if __name__ == "__main__":

with tempfile.TemporaryDirectory() as fwdir:
fwpath = download_and_extract_fw(dev_type, fwdir, fwuri=args.driver_uri)
shutil.copy(fwpath, python_validity_data)
shutil.copy(fwpath, PYTHON_VALIDITY_DATA_DIR)
4 changes: 3 additions & 1 deletion dbus_service/dbus-service
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ from usb import core as usb_core

from validitysensor import init
from validitysensor.db import subtype_to_string, db, SidIdentity, User
from validitysensor.init_data_dir import PYTHON_VALIDITY_DATA_DIR, init_data_dir
from validitysensor.sensor import sensor, RebootException
from validitysensor.sid import sid_from_string
from validitysensor.tls import tls
Expand All @@ -35,6 +36,7 @@ INTERFACE_NAME = 'io.github.uunicorn.Fprint.Device'

loop = GLib.MainLoop()

init_data_dir()

class NoEnrolledPrints(dbus.DBusException):
_dbus_error_name = 'net.reactivated.Fprint.Error.NoEnrolledPrints'
Expand Down Expand Up @@ -191,7 +193,7 @@ class Device(dbus.service.Object):
return hexlify(tls.app(unhexlify(cmd))).decode()


backoff_file = '/var/run/python-validity/backoff'
backoff_file = PYTHON_VALIDITY_DATA_DIR + 'backoff'


# I don't know how to tell systemd to backoff in case of multiple instance of the same template service, help!
Expand Down
1 change: 0 additions & 1 deletion debian/python3-validity.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set -e
#DEBHELPER#

if [ "$1" = "configure" ]; then
mkdir -p /var/run/python-validity || true
validity-sensors-firmware || true
systemctl daemon-reload || true
udevadm control --reload-rules || true
Expand Down
2 changes: 2 additions & 0 deletions validitysensor/init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import atexit
import logging

from validitysensor.init_data_dir import init_data_dir
from validitysensor.flash import read_tls_flash
from validitysensor.init_db import init_db
from validitysensor.init_flash import init_flash
Expand All @@ -26,6 +27,7 @@ def close():


def open_common():
init_data_dir()
init_flash()
usb.send_init()
tls.parse_tls_flash(read_tls_flash())
Expand Down
8 changes: 8 additions & 0 deletions validitysensor/init_data_dir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os

PYTHON_VALIDITY_DATA_DIR = '/var/run/python-validity/'

def init_data_dir():
if not os.path.isdir(PYTHON_VALIDITY_DATA_DIR):
os.mkdir(PYTHON_VALIDITY_DATA_DIR)

3 changes: 2 additions & 1 deletion validitysensor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
from .db import db, SidIdentity
from .flash import write_enable, call_cleanups, read_flash, erase_flash, write_flash_all, read_flash_all
from .hw_tables import dev_info_lookup
from .init_data_dir import PYTHON_VALIDITY_DATA_DIR
from .table_types import SensorTypeInfo, SensorCaptureProg
from .tls import tls
from .usb import usb, CancelledException
from .util import assert_status, unhex

# TODO: this should be specific to an individual device (system may have more than one sensor)
calib_data_path = '/var/run/python-validity/calib-data.bin'
calib_data_path = PYTHON_VALIDITY_DATA_DIR + 'calib-data.bin'

line_update_type1_devices = [
0xB5, 0x885, 0xB3, 0x143B, 0x1055, 0xE1, 0x8B1, 0xEA, 0xE4, 0xED, 0x1825, 0x1FF5, 0x199
Expand Down
3 changes: 2 additions & 1 deletion validitysensor/upload_fwext.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

from .firmware_tables import FIRMWARE_NAMES
from .flash import write_flash_all, write_fw_signature, get_fw_info
from .init_data_dir import PYTHON_VALIDITY_DATA_DIR
from .sensor import reboot, write_hw_reg32, read_hw_reg32, identify_sensor
from .usb import usb, SupportedDevices

firmware_home = '/var/run/python-validity'
firmware_home = PYTHON_VALIDITY_DATA_DIR


def default_fwext_name():
Expand Down

0 comments on commit ca21528

Please sign in to comment.