Skip to content

Commit

Permalink
Merge remote-tracking branch 'uploady/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
richo committed Feb 28, 2020
2 parents d2732ae + 46884c8 commit 14c749b
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
67 changes: 67 additions & 0 deletions src/bin/enumerate-media.rs
@@ -0,0 +1,67 @@
#[macro_use]
extern crate log;

use clap::{App, Arg};

use stokepile::cli;
use stokepile::config;
use stokepile::ctx::Ctx;
use stokepile::device;
use stokepile::mailer::MailReport;
use stokepile::mountable::Mountable;
use stokepile::staging::Stager;
use stokepile::storage;

fn cli_opts<'a, 'b>() -> App<'a, 'b> {
cli::base_opts()
.about("Performs a single run, uploading footage from all connected devices")
.arg(
Arg::with_name("no-cron")
.long("no-cron")
.help("Don't invoke any of the locking machinery to ensure only one stokepile runs at a time")
)
.arg(
Arg::with_name("stage-only")
.long("stage-only")
.help("Only stage files, do not process uploads")
)
}

fn main() {
stokepile::cli::run(|| {
let matches = cli_opts().get_matches();

let cfg = config::Config::from_file(matches.value_of("config").unwrap_or("stokepile.toml"));
let is_cron = !matches.is_present("no-cron");

let ctx = if is_cron {
Ctx::create(cfg?)?
} else {
Ctx::create_without_lock(cfg?)?
};

let devices = device::attached_devices(&ctx)?;

info!("Attached devices:");
for device in &devices {
info!(" {:?}", device);
}
info!("");

let backends = ctx.cfg.backends();
info!("Configured backends:");
for backend in &backends {
info!(" {:?}", backend);
}
info!("");

for device in devices {
info!("Device: {}", device.name());
for file in device.mass_storage_files()? {
info!(" {:?}", &file);
}
}

Ok(())
})
}
15 changes: 15 additions & 0 deletions src/device.rs
Expand Up @@ -7,6 +7,7 @@ use crate::ctx;
use crate::ptp_device;
use crate::staging::{StageFromDevice, StagingLocation, Stager};
use crate::mountable::{Mountable, MountableFilesystem};
use crate::mass_storage;

#[derive(Eq, PartialEq, Debug, Hash)]
pub struct DeviceDescription {
Expand Down Expand Up @@ -44,6 +45,20 @@ impl Device<'_> {
| Device::Flysight(ref desc, _) => &desc.name[..],
}
}

pub fn mass_storage_files(self) -> Result<Vec<mass_storage::MassStorageFile>, Error> {
match self {
Device::Gopro(desc, gopro) => {
unreachable!()
},
Device::MassStorage(desc, mass_storage) => {
Mountable::mount(mass_storage)?.files()
},
Device::Flysight(desc, flysight) => {
unreachable!()
},
}
}
}

pub fn attached_devices(ctx: &ctx::Ctx) -> Result<Vec<Device<'_>>, Error> {
Expand Down
16 changes: 15 additions & 1 deletion src/mass_storage.rs
@@ -1,5 +1,5 @@
use std::fs::{self, File};
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use crate::config::{MassStorageConfig, MountableDeviceLocation};
use crate::mountable::{MountableFilesystem, MountedFilesystem, MountableKind};
Expand Down Expand Up @@ -115,6 +115,20 @@ impl MountedMassStorage {
return None;
}

if let Some(Some(filename)) = path.file_name().map(|s|s.to_str()) {
if filename.starts_with("._") {
return None
}
}

for anc in path.ancestors() {
if let Some(Some(dirname)) = anc.file_name().map(|s|s.to_str()) {
if dirname == ".Trashes" {
return None
}
}
}

return Some(path.to_path_buf());
} else {
return None;
Expand Down
8 changes: 7 additions & 1 deletion src/ptp_device.rs
Expand Up @@ -291,7 +291,13 @@ pub fn locate_gopros(ctx: &ctx::Ctx) -> Result<Vec<Gopro<'_>>, Error> {
// ti's gunna be rough af.
#[cfg(feature = "usb")]
for device in ctx.usb_ctx.devices()?.iter() {
let device_desc = device.device_descriptor()?;
let device_desc = match device.device_descriptor() {
Ok(desc) => desc,
Err(e) => {
error!("Oh noes: {:?}", e.strerror());
Err(e)?
}
};

if device_desc.vendor_id() != GOPRO_VENDOR {
continue;
Expand Down

0 comments on commit 14c749b

Please sign in to comment.