Skip to content

Commit

Permalink
Don't grant write permissions when cloning git repo
Browse files Browse the repository at this point in the history
It should be unnecessary, the read-only flag is set on packfiles by Git
and doesn't cause problems deleting the folder normally, and someone's
reported an error when granting permissions.
  • Loading branch information
Ortham committed Sep 24, 2018
1 parent 3a747b8 commit ba90657
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 39 deletions.
39 changes: 1 addition & 38 deletions src/api/helpers/git_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ namespace fs = boost::filesystem;
namespace loot {
GitHelper::GitHelper() : logger_(getLogger()) {}

GitHelper::~GitHelper() {
if (data_.repo != nullptr) {
std::string path = git_repository_path(data_.repo);

if (!path.empty()) {
try {
GrantWritePermissions(path);
} catch (std::exception&) {
}
}
}
}

GitHelper::GitData::GitData() :
repo(nullptr),
remote(nullptr),
Expand Down Expand Up @@ -164,26 +151,6 @@ bool GitHelper::IsRepository(const boost::filesystem::path& path) {
NULL) == 0;
}

// Removes the read-only flag from some files in git repositories created by
// libgit2.
void GitHelper::GrantWritePermissions(const boost::filesystem::path& path) {
if (logger_) {
logger_->trace("Recursively setting write permission on directory: {}",
path.string());
}
for (fs::recursive_directory_iterator it(path);
it != fs::recursive_directory_iterator();
++it) {
if ((it->status().permissions() &
(fs::owner_write | fs::group_write | fs::others_write)) == 0) {
if (logger_) {
logger_->trace("Setting write permission for: {}", it->path().string());
}
fs::permissions(it->path(), fs::add_perms | fs::owner_write);
}
}
}

int GitHelper::DiffFileCallback(const git_diff_delta* delta,
float progress,
void* payload) {
Expand Down Expand Up @@ -248,13 +215,9 @@ void GitHelper::Clone(const boost::filesystem::path& path,

if (logger_) {
logger_->trace(
"Target repo path not empty, renaming and moving previous content "
"back in.");
"Target repo path not empty, moving cloned files in.");
}

GrantWritePermissions(path);
GrantWritePermissions(repoPath);

std::vector<boost::filesystem::path> filenamesToMove;
for (fs::directory_iterator it(repoPath);
it != fs::directory_iterator();
Expand Down
1 change: 0 additions & 1 deletion src/api/helpers/git_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace loot {
class GitHelper {
public:
GitHelper();
~GitHelper();

void InitialiseOptions(const std::string& branch,
const std::string& filenameToCheckout);
Expand Down

0 comments on commit ba90657

Please sign in to comment.