Skip to content

Commit

Permalink
optimized
Browse files Browse the repository at this point in the history
Signed-off-by: leleliu008 <[email protected]>
  • Loading branch information
leleliu008 committed Sep 10, 2023
1 parent a13a61e commit 54bbc12
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 168 deletions.
2 changes: 0 additions & 2 deletions src/cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <unistd.h>
#include <sys/stat.h>

#include "core/rm-r.h"

#include "uppm.h"

static int uppm_cleanup_downloads(bool verbose) {
Expand Down
91 changes: 0 additions & 91 deletions src/core/rm-r.c

This file was deleted.

14 changes: 0 additions & 14 deletions src/core/rm-r.h

This file was deleted.

8 changes: 4 additions & 4 deletions src/depends.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <sys/wait.h>
#include <sys/stat.h>

#include "core/rm-r.h"
#include "core/http.h"
#include "core/url.h"

Expand Down Expand Up @@ -356,9 +355,10 @@ static int uppm_depends2(const char * packageName, UPPMDependsOutputType outputT

if (stat(sessionDIR, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
if (rm_r(sessionDIR, false) != 0) {
perror(sessionDIR);
return UPPM_ERROR;
ret = uppm_rm_r(sessionDIR, false);

if (ret != UPPM_OK) {
return ret;
}
} else {
fprintf(stderr, "%s was expected to be a directory, but it was not.\n", sessionDIR);
Expand Down
8 changes: 4 additions & 4 deletions src/formula-repo-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <unistd.h>
#include <sys/stat.h>

#include "core/rm-r.h"
#include "core/log.h"

#include "uppm.h"
Expand Down Expand Up @@ -97,9 +96,10 @@ int uppm_formula_repo_add(const char * formulaRepoName, const char * formulaRepo

if (stat(sessionDIR, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
if (rm_r(sessionDIR, false) != 0) {
perror(sessionDIR);
return UPPM_ERROR;
ret = uppm_rm_r(sessionDIR, false);

if (ret != UPPM_OK) {
return ret;
}
} else {
fprintf(stderr, "%s was expected to be a directory, but it was not.\n", sessionDIR);
Expand Down
12 changes: 7 additions & 5 deletions src/formula-repo-create.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>

#include <git2.h>

#include "core/rm-r.h"
#include "core/log.h"

#include "uppm.h"
Expand Down Expand Up @@ -92,9 +93,10 @@ int uppm_formula_repo_create(const char * formulaRepoName, const char * formulaR

if (stat(sessionDIR, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
if (rm_r(sessionDIR, false) != 0) {
perror(sessionDIR);
return UPPM_ERROR;
ret = uppm_rm_r(sessionDIR, false);

if (ret != UPPM_OK) {
return ret;
}
} else {
fprintf(stderr, "%s was expected to be a directory, but it was not.\n", sessionDIR);
Expand Down
10 changes: 2 additions & 8 deletions src/formula-repo-remove.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

#include "core/rm-r.h"
#include <sys/stat.h>

#include "uppm.h"

Expand Down Expand Up @@ -48,12 +47,7 @@ int uppm_formula_repo_remove(const char * formulaRepoName) {
snprintf(formulaRepoConfigFilePath, formulaRepoConfigFilePathLength, "%s/.uppm-formula-repo.yml", formulaRepoPath);

if (stat(formulaRepoConfigFilePath, &st) == 0 && S_ISREG(st.st_mode)) {
if (rm_r(formulaRepoPath, false) == 0) {
return UPPM_OK;
} else {
perror(formulaRepoPath);
return UPPM_ERROR;
}
return uppm_rm_r(formulaRepoPath, false);
} else {
fprintf(stderr, "formula repo is broken: %s\n", formulaRepoName);
return UPPM_ERROR;
Expand Down
15 changes: 5 additions & 10 deletions src/generate-url-transform-sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <unistd.h>
#include <sys/stat.h>

#include "core/rm-r.h"
#include "core/log.h"

#include "uppm.h"
Expand Down Expand Up @@ -51,9 +50,10 @@ int uppm_generate_url_transform_sample() {

if (stat(sessionDIR, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
if (rm_r(sessionDIR, false) != 0) {
perror(sessionDIR);
return UPPM_ERROR;
ret = uppm_rm_r(sessionDIR, false);

if (ret != UPPM_OK) {
return ret;
}
} else {
fprintf(stderr, "%s was expected to be a directory, but it was not.\n", sessionDIR);
Expand Down Expand Up @@ -143,10 +143,5 @@ int uppm_generate_url_transform_sample() {

fprintf(stderr, "%sYou can rename url-transform.sample to url-transform then edit it to meet your needs.\n\nTo apply this, you should run 'export UPPM_URL_TRANSFORM=%s' in your terminal.\n%s", COLOR_GREEN, outFilePath, COLOR_OFF);

if (rm_r(sessionDIR, false) != 0) {
perror(sessionDIR);
return UPPM_ERROR;
}

return UPPM_OK;
return uppm_rm_r(sessionDIR, false);
}
14 changes: 8 additions & 6 deletions src/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "core/sysinfo.h"
#include "core/self.h"
#include "core/rm-r.h"
#include "core/tar.h"

#include "sha256sum.h"
Expand Down Expand Up @@ -244,9 +243,11 @@ int uppm_install(const char * packageName, bool verbose, bool force) {

if (lstat(packageInstalledRealDIR, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
if (rm_r(packageInstalledRealDIR, verbose) != 0) {
ret = uppm_rm_r(packageInstalledRealDIR, verbose);

if (ret != UPPM_OK) {
uppm_formula_free(formula);
return UPPM_ERROR;
return ret;
}
} else {
if (unlink(packageInstalledRealDIR) != 0) {
Expand Down Expand Up @@ -520,9 +521,10 @@ int uppm_install(const char * packageName, bool verbose, bool force) {
if (errno == EEXIST) {
if (lstat(packageName, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
if (rm_r (packageName, verbose) != 0) {
perror(packageName);
return UPPM_ERROR;
ret = uppm_rm_r(packageName, verbose);

if (ret != UPPM_OK) {
return ret;
}
} else {
if (unlink(packageName) != 0) {
Expand Down
9 changes: 4 additions & 5 deletions src/integrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <unistd.h>
#include <sys/stat.h>

#include "core/rm-r.h"

#include "uppm.h"

int uppm_integrate_zsh_completion(const char * outputDIR, bool verbose) {
Expand Down Expand Up @@ -49,9 +47,10 @@ int uppm_integrate_zsh_completion(const char * outputDIR, bool verbose) {

if (stat(sessionDIR, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
if (rm_r(sessionDIR, false) != 0) {
perror(sessionDIR);
return UPPM_ERROR;
ret = uppm_rm_r(sessionDIR, false);

if (ret != UPPM_OK) {
return ret;
}
} else {
fprintf(stderr, "%s was expected to be a directory, but it was not.\n", sessionDIR);
Expand Down
Loading

0 comments on commit 54bbc12

Please sign in to comment.