Skip to content

Commit

Permalink
Update uid/gid
Browse files Browse the repository at this point in the history
  • Loading branch information
teplofizik committed Apr 23, 2022
1 parent 94d8616 commit 9990be5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
16 changes: 16 additions & 0 deletions CpioLib/IO/CpioUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ private static void ProcessCommand(string[] Command, CpioArchive Archive)
Console.WriteLine($"ChMod {Path}: {ConvertModeToString(Mode)}");
}
break;
case "chown":
if (Command.Length == 3)
{
var Owner = Convert.ToUInt32(Command[2]);
Archive.ChOwn(Path, Owner);
Console.WriteLine($"ChOwn {Path}: {Owner}");
}
break;
case "group":
if (Command.Length == 3)
{
var Group = Convert.ToUInt32(Command[2]);
Archive.ChGroup(Path, Group);
Console.WriteLine($"Group {Path}: {Group}");
}
break;
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions CpioLib/Types/CpioArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ public void ChMod(string Filename, UInt32 Mode)
}
}

public void ChOwn(string Filename, UInt32 Uid)
{
var F = GetFile(Filename);
if (F != null)
{
F.UserId = Uid;
}
}
public void ChGroup(string Filename, UInt32 Gid)
{
var F = GetFile(Filename);
if (F != null)
{
F.GroupId = Gid;
}
}

public void AddDir(string Filename, string LocalPath)
{
Files.Add(new CpioFile(Filename, LocalPath, true));
Expand Down
25 changes: 23 additions & 2 deletions CpioLib/Types/CpioFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,29 @@ public UInt32 Mode
}
}

public UInt32 UserId => GetAsciiValue(22, 8);
public UInt32 GroupId => GetAsciiValue(30, 8);
public UInt32 UserId
{
get
{
return GetAsciiValue(22, 8);
}
set
{
SetAsciiValue(22, 8, value);
}
}
public UInt32 GroupId
{
get
{
return GetAsciiValue(30, 8);
}
set
{
SetAsciiValue(30, 8, value);
}
}

public UInt32 NumLink => GetAsciiValue(38, 8);
public UInt32 ModificationTime => GetAsciiValue(46, 8);

Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Available commands:
| ------------- | ------------- |------------- |
| rm | [path] | Remove file with specified path |
| chmod | [path] [mode] | Change mode of file ('rwxrwxrwx' format: user,group,other) |
| chown | [path] [uid] | Change user id of file |
| group | [path] [gid] | Change group id of file |

Content of image files will be replaced by content on file from root directory. Files that not exists in image, but exists in root directory will be added to image.

Expand Down

0 comments on commit 9990be5

Please sign in to comment.