Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
No0ne committed Dec 1, 2018
2 parents 70daebc + 2a56c45 commit cd8f734
Show file tree
Hide file tree
Showing 14 changed files with 311 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ make-image:
name: "sdimage-$CI_COMMIT_SHA"
paths:
- sdcard.img.zip
- rootfs.squashfs
- update.zip
- build.log
when: always
cache:
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
paths:
- buildroot/output/
- buildroot/output/
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ else
endif
git submodule > buildroot/output/.cache-version
zip -j sdcard.img.zip buildroot/output/images/sdcard.img
cp buildroot/output/images/rootfs.squashfs .

zip -j update.zip buildroot/output/images/zImage \
buildroot/output/images/rootfs.squashfs \
buildroot/output/images/initramfs.cpio.lzo
.PHONY: update-config
update-config:
cd "$(CURDIR)/buildroot" && cp "configs/piso_defconfig" ".config"
Expand Down
2 changes: 1 addition & 1 deletion buildroot
1 change: 1 addition & 0 deletions pISO/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.3.0
6 changes: 6 additions & 0 deletions pISO/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ pub enum Action {
ToggleDriveNonRemovable(String),

FlipDisplay,

OpenVersion,
CloseVersion,

SmbSharePartition(String),
SmbRemoveShare(String),
}
9 changes: 6 additions & 3 deletions pISO/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ where

#[derive(Clone, Debug, Deserialize)]
pub struct UiConfig {
pub size_step: u32,
pub default_size: u32,
pub size_step: f32,
pub default_size: f32,

#[serde(deserialize_with = "from_millis")]
pub min_button_press: time::Duration,

#[serde(deserialize_with = "from_millis")]
pub button_long_press: time::Duration,

pub sort_drives: Option<bool>,
}

#[derive(Clone, Debug, Deserialize)]
Expand Down Expand Up @@ -77,6 +79,7 @@ mod tests {
default_size=50
min_button_press=300
button_long_press=2000
sort_drives=true
[system]
auto_fstrim=true
Expand Down Expand Up @@ -113,7 +116,7 @@ mod tests {
fn load_with_no_wifi_client() {
let toml_str = r#"
[ui]
size_step=5
size_step=4.2
default_size=50
min_button_press=300
button_long_press=2000
Expand Down
2 changes: 1 addition & 1 deletion pISO/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn run(manager: &mut displaymanager::DisplayManager) -> error::Result<()> {
manufacturer: "Adam Schwalm & James Tate",
product: "pISO",

max_power: "250",
max_power: "500",
configuration: "Config 1",
},
)?));
Expand Down
8 changes: 5 additions & 3 deletions pISO/src/newdrive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ enum DriveSizeState {

struct DriveSize {
pub window: WindowId,
pub current_percent: u32,
pub current_percent: f32,
pub usb: Arc<Mutex<usb::UsbGadget>>,
vg: lvm::VolumeGroup,
state: DriveSizeState,
Expand All @@ -149,7 +149,7 @@ impl DriveSize {

fn current_size(&self) -> u64 {
let bytes = self.vg.report().expect("Failed to get vg report").vg_size as f32
* (self.current_percent as f32 / 100.0);
* (self.current_percent / 100.0);
((bytes as u64 + 512 - 1) / 512) * 512
}
}
Expand Down Expand Up @@ -192,7 +192,9 @@ impl input::Input for DriveSize {
Ok((true, vec![]))
}
action::Action::DecDriveSize => {
self.current_percent -= self.config.ui.size_step;
if self.current_percent - self.config.ui.size_step > 0.0 {
self.current_percent -= self.config.ui.size_step;
}
Ok((true, vec![]))
}
action::Action::OpenFormatMenu => {
Expand Down
7 changes: 7 additions & 0 deletions pISO/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use input;
use lvm;
use render;
use state;
use version;

pub struct Options {
window: WindowId,
Expand All @@ -18,6 +19,7 @@ pub struct Options {
removable: buttons::vdrivelist::DriveList,
delete: buttons::vdrivelist::DriveList,
snapshot: buttons::vdrivelist::DriveList,
version: version::VersionMenu,
}

impl Options {
Expand Down Expand Up @@ -68,13 +70,16 @@ impl Options {
config.clone(),
)?;

let version = version::VersionMenu::new(disp)?;

Ok(Options {
window: our_window,
open: false,
readonly: readonly,
removable: removable,
delete: delete,
snapshot: snapshot,
version: version,
})
}
}
Expand Down Expand Up @@ -115,6 +120,7 @@ impl Widget for Options {
&mut self.removable as &mut Widget,
&mut self.snapshot as &mut Widget,
&mut self.delete as &mut Widget,
&mut self.version as &mut Widget,
]
} else {
vec![]
Expand All @@ -128,6 +134,7 @@ impl Widget for Options {
&self.removable as &Widget,
&self.snapshot as &Widget,
&self.delete as &Widget,
&self.version as &Widget,
]
} else {
vec![]
Expand Down
87 changes: 73 additions & 14 deletions pISO/src/piso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,48 @@ impl PIso {
Ok(drives)
}

fn add_drive(
&mut self,
disp: &mut DisplayManager,
fn add_drive<'a, 'b>(
&'a mut self,
disp: &'b mut DisplayManager,
volume: lvm::LogicalVolume,
) -> Result<&vdrive::VirtualDrive> {
let vdrive = vdrive::VirtualDrive::new(disp, self.usb.clone(), volume, &self.config)?;
) -> Result<&'a mut vdrive::VirtualDrive> {
let mut vdrive = vdrive::VirtualDrive::new(disp, self.usb.clone(), volume, &self.config)?;
vdrive.mount_internal(disp)?;
self.drives.push(vdrive);

Ok(self.drives
.last()
.last_mut()
.expect("vdrive was somehow empty after push"))
}

fn share_drive(drive: &mut vdrive::VirtualDrive, remove: bool) -> Result<Vec<action::Action>> {
if !version::read_version()?.has_wifi() {
return Ok(vec![]);
}
match drive.state {
vdrive::MountState::Unmounted | vdrive::MountState::External(_) => {
if remove {
Ok(vec![])
} else {
Err("Cannot share drive when not mounted internal".into())
}
}
vdrive::MountState::Internal(ref info) => Ok(info.part_mount_paths
.iter()
.map(|path| {
let name = path.file_name()
.expect("Partition has no name")
.to_string_lossy()
.into_owned();
if remove {
action::Action::SmbRemoveShare(name)
} else {
action::Action::SmbSharePartition(name)
}
})
.collect()),
}
}
}

impl render::Render for PIso {
Expand All @@ -145,23 +175,27 @@ impl input::Input for PIso {
Ok((true, vec![]))
}
action::Action::CreateDrive(ref volume) => {
self.add_drive(disp, volume.clone())?;
Ok((true, vec![]))
let drive = self.add_drive(disp, volume.clone())?;
let actions = PIso::share_drive(drive, false)?;
Ok((true, actions))
}
action::Action::SnapshotDrive(ref name) => {
let report = self.vg.snapshot_volume(name)?;
self.add_drive(disp, report)?;
Ok((true, vec![]))
let drive = self.add_drive(disp, report)?;
let actions = PIso::share_drive(drive, false)?;
Ok((true, actions))
}
action::Action::DeleteDrive(ref name) => {
let mut actions = vec![];
if let Some(ref mut drive) =
self.drives.iter_mut().find(|drive| drive.name() == name)
{
actions = PIso::share_drive(drive, true)?;
drive.unmount()?;
}
self.drives.retain(|drive| drive.name() != name);
self.vg.delete_volume(&name)?;
Ok((true, vec![]))
Ok((true, actions))
}
_ => Ok((false, vec![])),
}
Expand All @@ -172,10 +206,22 @@ impl state::State for PIso {}

impl Widget for PIso {
fn mut_children(&mut self) -> Vec<&mut Widget> {
let mut children = self.drives
.iter_mut()
let mut ordered_children = self.drives
.iter_mut()
.collect::<Vec<&mut vdrive::VirtualDrive>>();

match self.config.ui.sort_drives {
Some(true) => ordered_children.sort_by(|drive1, drive2| {
drive1.volume.name.cmp(&drive2.volume.name)
}),
_ => ()
}

let mut children = ordered_children
.into_iter()
.map(|vdrive| vdrive as &mut Widget)
.collect::<Vec<&mut Widget>>();

children.push(&mut self.newdrive as &mut Widget);
if self.version.has_wifi() {
children.push(&mut self.wifi as &mut Widget);
Expand All @@ -186,10 +232,23 @@ impl Widget for PIso {
}

fn children(&self) -> Vec<&Widget> {
let mut children = self.drives
let mut ordered_children = self.drives
.iter()
.collect::<Vec<&vdrive::VirtualDrive>>();

match self.config.ui.sort_drives {
Some(true) => ordered_children.sort_by(|drive1, drive2| {
utils::translate_drive_name(&drive1.volume.name, &self.config).cmp(
&utils::translate_drive_name(&drive2.volume.name, &self.config))
}),
_ => ()
}

let mut children = ordered_children
.into_iter()
.map(|vdrive| vdrive as &Widget)
.collect::<Vec<&Widget>>();

children.push(&self.newdrive as &Widget);
if self.version.has_wifi() {
children.push(&self.wifi as &Widget);
Expand Down
2 changes: 1 addition & 1 deletion pISO/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl render::Render for Stats {
fn render(&self, _manager: &DisplayManager, _window: &Window) -> error::Result<bitmap::Bitmap> {
let mut base = bitmap::Bitmap::new(0, 0);
let percent_free = 100.0 - self.vg.pool()?.data_percent;
let contents = font::render_text(format!("{}% Free", percent_free));
let contents = font::render_text(format!("{}% Free", percent_free as u64));
base.blit(&contents, (0, 0));
Ok(base.rotate(bitmap::Direction::Left))
}
Expand Down
16 changes: 12 additions & 4 deletions pISO/src/vdrive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ impl VirtualDrive {
).into())
}

pub fn mount_internal(&mut self, disp: &mut DisplayManager) -> Result<()> {
pub fn mount_internal<'a, 'b>(
&'a mut self,
disp: &'b mut DisplayManager,
) -> Result<&'a MountInfo> {
match self.state {
MountState::Unmounted => {
let volume_path = &self.volume.path.to_string_lossy();
Expand Down Expand Up @@ -222,9 +225,12 @@ impl VirtualDrive {
isos: isos,
loopback_path: loopback_path.to_path_buf(),
});
Ok(())
match &self.state {
&MountState::Internal(ref info) => Ok(info),
_ => unreachable!(),
}
}
MountState::Internal(_) => Ok(()),
MountState::Internal(ref state) => Ok(state),
MountState::External(_) => {
Err("Attempt to mount_internal while mounted external".into())
}
Expand All @@ -240,6 +246,7 @@ impl VirtualDrive {
}
for part in info.part_mount_paths.iter() {
utils::run_check_output("umount", &[&part])?;
fs::remove_dir_all(&part)?;
}
utils::run_check_output("losetup", &["-d", &info.loopback_path.to_string_lossy()])?;
}
Expand All @@ -261,7 +268,8 @@ impl VirtualDrive {
}
MountState::External(_) => {
self.unmount_external()?;
self.mount_internal(disp)
self.mount_internal(disp)?;
Ok(())
}
}
}
Expand Down
Loading

0 comments on commit cd8f734

Please sign in to comment.