@@ -49,10 +49,8 @@ pub(crate) fn xdg_config() -> Result<PathBuf, Error> {
49
49
pub ( crate ) fn aura_config ( ) -> Result < PathBuf , Error > {
50
50
let xdg = xdg_config ( ) ?;
51
51
let dir = xdg. join ( "aura" ) ;
52
-
53
- if dir. is_dir ( ) . not ( ) {
54
- std:: fs:: create_dir_all ( & dir) . map_err ( |e| Error :: Mkdir ( dir. clone ( ) , e) ) ?;
55
- }
52
+
53
+ make_dir ( & dir) ?;
56
54
57
55
Ok ( dir. join ( "config.toml" ) )
58
56
}
@@ -72,74 +70,48 @@ fn xdg_cache() -> Result<PathBuf, Error> {
72
70
73
71
/// The full path to the Aura cache.
74
72
pub ( crate ) fn aura_xdg_cache ( ) -> Result < PathBuf , Error > {
75
- let cache = xdg_cache ( ) ?. join ( "aura" ) ;
76
- Ok ( cache)
73
+ Ok ( xdg_cache ( ) ?. join ( "aura" ) )
77
74
}
78
75
79
76
/// The full path to the package snapshot directory.
80
77
///
81
- /// Creates the directory if it doesn't exist.
82
78
pub ( crate ) fn snapshot ( ) -> Result < PathBuf , Error > {
83
- let path = aura_xdg_cache ( ) ?. join ( "snapshots" ) ;
84
-
85
- if path. is_dir ( ) . not ( ) {
86
- std:: fs:: create_dir_all ( & path) . map_err ( |e| Error :: Mkdir ( path. clone ( ) , e) ) ?;
87
- }
88
-
89
- Ok ( path)
79
+ Ok ( aura_xdg_cache ( ) ?. join ( "snapshots" ) )
90
80
}
91
81
92
82
/// The full path to the directory of AUR package `git` clones.
93
83
///
94
- /// Creates the directory if it doesn't exist.
95
84
pub ( crate ) fn clones ( ) -> Result < PathBuf , Error > {
96
85
let path = std:: env:: var ( "AURDEST" )
97
86
. map ( PathBuf :: from)
98
87
. or_else ( |_| aura_xdg_cache ( ) . map ( |p| p. join ( "packages" ) ) ) ?;
99
88
100
- if path. is_dir ( ) . not ( ) {
101
- std:: fs:: create_dir_all ( & path) . map_err ( |e| Error :: Mkdir ( path. clone ( ) , e) ) ?;
102
- }
103
-
104
89
Ok ( path)
105
90
}
106
91
107
92
/// The full path to the build directory.
108
93
///
109
- /// Creates the directory if it doesn't exist.
110
94
pub ( crate ) fn builds ( ) -> Result < PathBuf , Error > {
111
- let path = aura_xdg_cache ( ) ?. join ( "builds" ) ;
112
-
113
- if path. is_dir ( ) . not ( ) {
114
- std:: fs:: create_dir_all ( & path) . map_err ( |e| Error :: Mkdir ( path. clone ( ) , e) ) ?;
115
- }
116
-
117
- Ok ( path)
95
+ Ok ( aura_xdg_cache ( ) ?. join ( "builds" ) )
118
96
}
119
97
120
98
/// The full path to the Aura-specific tarball cache.
121
99
///
122
- /// Creates the directory if it doesn't exist.
123
100
pub ( crate ) fn tarballs ( ) -> Result < PathBuf , Error > {
124
- let path = aura_xdg_cache ( ) ?. join ( "cache" ) ;
125
-
126
- if path. is_dir ( ) . not ( ) {
127
- std:: fs:: create_dir_all ( & path) . map_err ( |e| Error :: Mkdir ( path. clone ( ) , e) ) ?;
128
- }
129
-
130
- Ok ( path)
101
+ Ok ( aura_xdg_cache ( ) ?. join ( "cache" ) )
131
102
}
132
103
133
104
/// The full path to the directory of git hashes that indicate the last time an
134
105
/// AUR package was built and installed.
135
106
///
136
- /// Creates the directory if it doesn't exist.
137
107
pub ( crate ) fn hashes ( ) -> Result < PathBuf , Error > {
138
- let path = aura_xdg_cache ( ) ?. join ( "hashes" ) ;
108
+ Ok ( aura_xdg_cache ( ) ?. join ( "hashes" ) )
109
+ }
139
110
111
+ /// Create a directory if it doesn't exist.
112
+ pub ( crate ) fn make_dir ( path : & PathBuf ) -> Result < ( ) , Error > {
140
113
if path. is_dir ( ) . not ( ) {
141
114
std:: fs:: create_dir_all ( & path) . map_err ( |e| Error :: Mkdir ( path. clone ( ) , e) ) ?;
142
115
}
143
-
144
- Ok ( path)
145
- }
116
+ Ok ( ( ) )
117
+ }
0 commit comments