Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
steam-runtime-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
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
steamrt
steam-runtime-tools
Commits
376219a9
Commit
376219a9
authored
10 years ago
by
Colin Walters
Browse files
Options
Downloads
Patches
Plain Diff
fdio: Also add a replace variant that takes mode/uid/gid
This will be used for OSTree too.
parent
dc47528f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
glnx-fdio.c
+50
-8
50 additions, 8 deletions
glnx-fdio.c
glnx-fdio.h
+12
-1
12 additions, 1 deletion
glnx-fdio.h
with
62 additions
and
9 deletions
glnx-fdio.c
+
50
−
8
View file @
376219a9
...
...
@@ -587,7 +587,7 @@ glnx_file_copy_at (int src_dfd,
}
/**
* glnx_file_replace_contents_
utf8_
at:
* glnx_file_replace_contents_at:
* @dfd: Directory fd
* @subpath: Subpath
* @buf: (array len=len) (element-type guint8): File contents
...
...
@@ -609,10 +609,40 @@ glnx_file_replace_contents_at (int dfd,
const
char
*
subpath
,
const
guint8
*
buf
,
gsize
len
,
int
mode
,
GLnxFileReplaceFlags
flags
,
GCancellable
*
cancellable
,
GError
**
error
)
{
return
glnx_file_replace_contents_with_perms_at
(
dfd
,
subpath
,
buf
,
len
,
(
mode_t
)
-
1
,
(
uid_t
)
-
1
,
(
gid_t
)
-
1
,
flags
,
cancellable
,
error
);
}
/**
* glnx_file_replace_contents_with_perms_at:
* @dfd: Directory fd
* @subpath: Subpath
* @buf: (array len=len) (element-type guint8): File contents
* @len: Length (if `-1`, assume @buf is `NUL` terminated)
* @flags: Flags
* @cancellable: Cancellable
* @error: Error
*
* Like glnx_file_replace_contents_at(), but also supports
* setting mode, and uid/gid.
*/
gboolean
glnx_file_replace_contents_with_perms_at
(
int
dfd
,
const
char
*
subpath
,
const
guint8
*
buf
,
gsize
len
,
mode_t
mode
,
uid_t
uid
,
gid_t
gid
,
GLnxFileReplaceFlags
flags
,
GCancellable
*
cancellable
,
GError
**
error
)
{
gboolean
ret
=
FALSE
;
/* We use the /proc/self trick as there's no mkostemp_at() yet */
...
...
@@ -625,12 +655,6 @@ glnx_file_replace_contents_at (int dfd,
goto
out
;
}
if
(
fchmod
(
fd
,
mode
)
!=
0
)
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
if
(
len
==
-
1
)
len
=
strlen
((
char
*
)
buf
);
...
...
@@ -673,6 +697,24 @@ glnx_file_replace_contents_at (int dfd,
}
}
if
(
uid
!=
(
uid_t
)
-
1
)
{
if
(
fchown
(
fd
,
uid
,
gid
)
!=
0
)
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
}
if
(
mode
!=
(
mode_t
)
-
1
)
{
if
(
fchmod
(
fd
,
mode
)
!=
0
)
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
}
if
(
renameat
(
dfd
,
tmppath
,
dfd
,
subpath
)
!=
0
)
{
glnx_set_error_from_errno
(
error
);
...
...
This diff is collapsed.
Click to expand it.
glnx-fdio.h
+
12
−
1
View file @
376219a9
...
...
@@ -80,11 +80,22 @@ glnx_file_replace_contents_at (int dfd,
const
char
*
subpath
,
const
guint8
*
buf
,
gsize
len
,
int
mode
,
GLnxFileReplaceFlags
flags
,
GCancellable
*
cancellable
,
GError
**
error
);
gboolean
glnx_file_replace_contents_with_perms_at
(
int
dfd
,
const
char
*
subpath
,
const
guint8
*
buf
,
gsize
len
,
mode_t
mode
,
uid_t
uid
,
gid_t
gid
,
GLnxFileReplaceFlags
flags
,
GCancellable
*
cancellable
,
GError
**
error
);
char
*
glnx_readlinkat_malloc
(
int
dfd
,
const
char
*
subpath
,
...
...
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