Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
installer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
installer
Commits
a4adb124
Unverified
Commit
a4adb124
authored
7 years ago
by
Ian Douglas Scott
Browse files
Options
Downloads
Patches
Plain Diff
Support adding symlinks in configuration
I'm not sure if this is the best syntax...
parent
5cfe3578
Branches
Branches containing commit
No related tags found
1 merge request
!5
Support adding symlinks in configuration
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/config/file.rs
+3
-1
3 additions, 1 deletion
src/config/file.rs
src/install.rs
+14
-6
14 additions, 6 deletions
src/install.rs
with
17 additions
and
7 deletions
src/config/file.rs
+
3
−
1
View file @
a4adb124
#[derive(Debug,
Default,
Deserialize)]
#[derive(Debug,
Default,
Deserialize)]
pub
struct
FileConfig
{
pub
struct
FileConfig
{
pub
path
:
String
,
pub
path
:
String
,
pub
data
:
String
pub
data
:
String
,
#[serde(default)]
pub
symlink
:
bool
}
}
This diff is collapsed.
Click to expand it.
src/install.rs
+
14
−
6
View file @
a4adb124
...
@@ -12,6 +12,9 @@ use std::{env, fs};
...
@@ -12,6 +12,9 @@ use std::{env, fs};
use
std
::
io
::{
self
,
stderr
,
Write
};
use
std
::
io
::{
self
,
stderr
,
Write
};
use
std
::
str
::
FromStr
;
use
std
::
str
::
FromStr
;
use
std
::
process
::{
self
,
Command
};
use
std
::
process
::{
self
,
Command
};
use
std
::
os
::
unix
::
fs
::
symlink
;
use
std
::
os
::
unix
::
ffi
::
OsStrExt
;
use
std
::
ffi
::
OsStr
;
use
config
::
Config
;
use
config
::
Config
;
...
@@ -134,16 +137,21 @@ pub fn install(config: Config, cookbook: Option<&str>) -> Result<(), String> {
...
@@ -134,16 +137,21 @@ pub fn install(config: Config, cookbook: Option<&str>) -> Result<(), String> {
}
}
macro_rules!
file
{
macro_rules!
file
{
(
$path:expr
,
$data:expr
)
=>
{{
(
$path:expr
,
$data:expr
,
$symlink:expr
)
=>
{{
let
mut
path
=
sysroot
.clone
();
let
mut
path
=
sysroot
.clone
();
path
.push
(
$path
);
path
.push
(
$path
);
if
let
Some
(
parent
)
=
path
.parent
()
{
if
let
Some
(
parent
)
=
path
.parent
()
{
println!
(
"Create file parent {}"
,
parent
.display
());
println!
(
"Create file parent {}"
,
parent
.display
());
fs
::
create_dir_all
(
parent
)
.map_err
(|
err
|
format!
(
"failed to create file parent {}: {}"
,
parent
.display
(),
err
))
?
;
fs
::
create_dir_all
(
parent
)
.map_err
(|
err
|
format!
(
"failed to create file parent {}: {}"
,
parent
.display
(),
err
))
?
;
}
}
println!
(
"Create file {}"
,
path
.display
());
if
$symlink
{
let
mut
file
=
fs
::
File
::
create
(
&
path
)
.map_err
(|
err
|
format!
(
"failed to create {}: {}"
,
path
.display
(),
err
))
?
;
println!
(
"Create symlink {}"
,
path
.display
());
file
.write_all
(
$data
)
.map_err
(|
err
|
format!
(
"failed to write {}: {}"
,
path
.display
(),
err
))
?
;
symlink
(
&
OsStr
::
from_bytes
(
$data
),
&
path
)
.map_err
(|
err
|
format!
(
"failed to symlink {}: {}"
,
path
.display
(),
err
))
?
;
}
else
{
println!
(
"Create file {}"
,
path
.display
());
let
mut
file
=
fs
::
File
::
create
(
&
path
)
.map_err
(|
err
|
format!
(
"failed to create {}: {}"
,
path
.display
(),
err
))
?
;
file
.write_all
(
$data
)
.map_err
(|
err
|
format!
(
"failed to write {}: {}"
,
path
.display
(),
err
))
?
;
}
}};
}};
}
}
...
@@ -152,7 +160,7 @@ pub fn install(config: Config, cookbook: Option<&str>) -> Result<(), String> {
...
@@ -152,7 +160,7 @@ pub fn install(config: Config, cookbook: Option<&str>) -> Result<(), String> {
install_packages
(
&
config
,
sysroot
.to_str
()
.unwrap
(),
cookbook
);
install_packages
(
&
config
,
sysroot
.to_str
()
.unwrap
(),
cookbook
);
for
file
in
config
.files
{
for
file
in
config
.files
{
file!
(
file
.path
.trim_matches
(
'/'
),
file
.data
.as_bytes
());
file!
(
file
.path
.trim_matches
(
'/'
),
file
.data
.as_bytes
()
,
file
.symlink
);
}
}
let
mut
passwd
=
String
::
new
();
let
mut
passwd
=
String
::
new
();
...
@@ -191,7 +199,7 @@ pub fn install(config: Config, cookbook: Option<&str>) -> Result<(), String> {
...
@@ -191,7 +199,7 @@ pub fn install(config: Config, cookbook: Option<&str>) -> Result<(), String> {
passwd
.push_str
(
&
format!
(
"{};{};{};{};{};{};{}
\n
"
,
username
,
password
,
uid
,
gid
,
name
,
home
,
shell
));
passwd
.push_str
(
&
format!
(
"{};{};{};{};{};{};{}
\n
"
,
username
,
password
,
uid
,
gid
,
name
,
home
,
shell
));
}
}
if
!
passwd
.is_empty
()
{
if
!
passwd
.is_empty
()
{
file!
(
"etc/passwd"
,
passwd
.as_bytes
());
file!
(
"etc/passwd"
,
passwd
.as_bytes
()
,
false
);
}
}
Ok
(())
Ok
(())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment