Skip to content

Commit

Permalink
Allow file update by [file] command, show file modes in empty extract…
Browse files Browse the repository at this point in the history
… arg
  • Loading branch information
teplofizik committed May 12, 2022
1 parent 3773946 commit 500bb5b
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions CpioLib/IO/CpioUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ public static void Info(ref CpioArchive Archive)
{
foreach (var F in Archive.Files)
{
Console.WriteLine($"{F.Path}: m:{F.Mode:x02} in:{F.INode} links:{F.NumLink} maj:{F.Major} min:{F.Minor} rmaj:{F.RMajor} rmin:{F.RMinor}");
var Mode = F.Mode & 0x1FFU;
uint DstMode = 0;
DstMode |= (Mode & 0x7);
DstMode |= ((Mode >> 3) & 0x7) << 4;
DstMode |= ((Mode >> 6) & 0x7) << 8;

var TMode = ConvertModeToString(DstMode);

Console.WriteLine($"{F.Path}: {TMode} m:{F.Mode:x02} in:{F.INode} links:{F.NumLink} maj:{F.Major} min:{F.Minor} rmaj:{F.RMajor} rmin:{F.RMinor}");
}
}

Expand Down Expand Up @@ -225,6 +233,7 @@ private static void ProcessCommand(string CmdPath, string[] Command, CpioArchive
break;
case "file":
// file /init ./content/init 755 0 0
// file [path] [filepath]
// file [path] [filepath] [mode] [uid] [gid]
if (Command.Length == 6)
{
Expand All @@ -237,7 +246,12 @@ private static void ProcessCommand(string CmdPath, string[] Command, CpioArchive
var ExFile = Archive.GetFile(Path);
if (ExFile != null)
{
Console.WriteLine($"File {Path} already exists");
Archive.UpdateFile(Path, LocalPath);
Archive.ChMod(Path, Mode);
Archive.ChOwn(Path, Owner);
Archive.ChGroup(Path, Group);

Console.WriteLine($"File {Path}: updated by {LocalPath} m:{ ConvertModeToString(Mode) } u:{Owner} g:{Group}");
}
else
{
Expand All @@ -254,6 +268,28 @@ private static void ProcessCommand(string CmdPath, string[] Command, CpioArchive
Console.WriteLine($"File {Path}: file {LocalPath} not found");
}
}
else if (Command.Length == 3)
{
var LocalPath = Command[2];
if (File.Exists(LocalPath))
{
var ExFile = Archive.GetFile(Path);
if (ExFile != null)
{
Archive.UpdateFile(Path, LocalPath);

Console.WriteLine($"File {Path}: updated by {LocalPath}");
}
else
{
Console.WriteLine($"File {Path}: file not found, unable to modify");
}
}
else
{
Console.WriteLine($"File {Path}: file {LocalPath} not found");
}
}
else
{
Console.WriteLine($"File {Path}: need {5} arguments, {Command.Length-1} given");
Expand Down

0 comments on commit 500bb5b

Please sign in to comment.