Skip to content

Commit

Permalink
Use Git-based repository for git-lfs-transfer
Browse files Browse the repository at this point in the history
Now that we have a Git-based repository, use it for `git-lfs-transfer`.
This adds SHA-256 repository support and also allows us to process
repositories that are not owned by the current user.

Note that because we call a bare program name, it's not safe to use this
software on Windows because of a Rust vulnerability.

Signed-off-by: brian m. carlson <[email protected]>
  • Loading branch information
bk2204 committed Jan 8, 2024
1 parent 4db6d5b commit 3fcea6f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
7 changes: 7 additions & 0 deletions scutiger-core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![allow(bare_trait_objects)]
#![allow(clippy::upper_case_acronyms)]

use crate::repository;
use std::convert;
use std::error;
use std::fmt;
Expand Down Expand Up @@ -187,6 +188,12 @@ impl convert::From<git2::Error> for Error {
}
}

impl convert::From<repository::Error> for Error {
fn from(error: repository::Error) -> Self {
Error::new(ErrorKind::GitError, Some(error))
}
}

#[cfg(feature = "pcre")]
impl convert::From<pcre2::Error> for Error {
fn from(error: pcre2::Error) -> Self {
Expand Down
4 changes: 4 additions & 0 deletions scutiger-lfs/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ At this moment, the implementation does not support locking and it remains exper
This utility should be fully functional on Unix systems, with the normal Git-related exceptions about case-insensitive systems.
It is tested to build on Windows only with a minimal stable Rust toolchain, provided Windows 10 or 11 with Developer Mode is used.
https://github.com/bk2204/.github/blob/dev/SUPPORTED.adoc[The supported platforms policy] otherwise applies.

Note well that https://github.com/rust-lang/rust/issues/87945[Rust has a security problem invoking binaries without an absolute path on Windows].
Until Rust is fixed, this software should not be used on Windows since it may execute arbitrary code.
This is a vulnerability in Rust and will not be treated as a vulnerability in this software.
23 changes: 11 additions & 12 deletions scutiger-lfs/src/bin/git-lfs-transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ extern crate tempfile;
extern crate pretty_assertions;

use clap::{App, Arg, ArgMatches};
use git2::Repository;
use scutiger_core::errors::{Error, ErrorKind, ExitStatus};
use scutiger_core::repository::Repository;
use scutiger_lfs::backend::local::LocalBackend;
use scutiger_lfs::processor::{Mode, PktLineHandler, Processor};
use std::fs;
Expand Down Expand Up @@ -97,16 +97,14 @@ impl<'p> Program<'p> {
fn set_permissions(&self) -> Result<u32, Error> {
let config = self.repo.config()?;
let sval = config.get_string("core.sharedrepository");
let tval = sval.as_ref().map(|s| s.as_str());
let perms = match (config.get_bool("core.sharedrepository"), tval) {
(Ok(true), _) | (_, Ok("group")) => Some(0o660),
(Ok(false), _) | (_, Ok("umask")) => None,
(_, Ok("all")) | (_, Ok("world")) | (_, Ok("everybody")) => Some(0o664),
(_, Ok(x)) if u16::from_str_radix(x, 8).is_ok() => {
let perms = match (config.get_bool("core.sharedrepository"), sval) {
(Some(true), _) | (_, Some("group")) => Some(0o660),
(Some(false), _) | (_, Some("umask")) => None,
(_, Some("all")) | (_, Some("world")) | (_, Some("everybody")) => Some(0o664),
(_, Some(x)) if u16::from_str_radix(x, 8).is_ok() => {
Some(u16::from_str_radix(x, 8).unwrap())
}
(_, Err(e)) if e.code() == git2::ErrorCode::NotFound => None,
(_, Err(e)) => return Err(git2::Error::new(e.code(), e.class(), e.message()).into()),
(_, None) => None,
_ => None,
};
let res = match perms {
Expand Down Expand Up @@ -174,7 +172,7 @@ fn program<'a>(r: &'a Repository, matches: &'a ArgMatches) -> Program<'a> {
}

fn repo<P: AsRef<Path>>(path: P) -> Repository {
let repo = git2::Repository::open(path);
let repo = Repository::discover(path, true);
match repo {
Ok(r) => r,
Err(e) => {
Expand Down Expand Up @@ -207,7 +205,7 @@ fn main() {
#[cfg(test)]
mod tests {
use super::{Error, Program};
use git2::Repository;
use scutiger_core::repository::Repository;
use std::fs;
use std::io;
use std::io::Read;
Expand All @@ -221,7 +219,8 @@ mod tests {
impl TestRepository {
pub fn new() -> TestRepository {
let dir = tempfile::tempdir().unwrap();
let repo = Repository::init(dir.path()).unwrap();
git2::Repository::init(dir.path()).unwrap();
let repo = Repository::discover(dir.path(), true).unwrap();
TestRepository { repo, tempdir: dir }
}
}
Expand Down

0 comments on commit 3fcea6f

Please sign in to comment.