Skip to content

Commit 92a4516

Browse files
File touch working
1 parent 0b10559 commit 92a4516

15 files changed

+441
-963
lines changed

build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ if (!$SkipBuild) {
262262
"osinfo",
263263
"powershell-adapter",
264264
"process",
265-
"resources/fs",
265+
"resources/filesys",
266266
"runcommandonset",
267267
"tools/dsctest",
268268
"tools/test_group_resource",

dsc/examples/filesys_create.dsc.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Example configuration mixing native app resources with classic PS resources
2+
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
3+
resources:
4+
- name: Create empty file
5+
type: Microsoft.DSC/File
6+
properties:
7+
path: "[path('d:\\', 'temp', 'a.txt')]"
8+
_exist: true

resources/fs/fs.dsc.resource.json renamed to resources/filesys/directory.dsc.resource.json

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json",
3-
"type": "Microsoft.DSC/FileSystem",
4-
"description": "Manage file system configuration settings.",
3+
"type": "Microsoft.DSC/Directory",
4+
"description": "Manage directory configuration settings.",
55
"version": "0.1.0",
66
"get": {
7-
"executable": "fs",
7+
"executable": "filesys",
88
"args": [
99
"get",
1010
{
@@ -16,7 +16,7 @@
1616
"implementsPretest": false
1717
},
1818
"delete": {
19-
"executable": "fs",
19+
"executable": "filesys",
2020
"args": [
2121
"delete",
2222
{
@@ -26,11 +26,24 @@
2626
],
2727
"input": "stdin"
2828
},
29+
"set": {
30+
"executable": "filesys",
31+
"args": [
32+
"set",
33+
{
34+
"jsonInputArg": "--input",
35+
"mandatory": true
36+
}
37+
],
38+
"input": "stdin"
39+
},
2940
"schema": {
3041
"command": {
31-
"executable": "fs",
42+
"executable": "filesys",
3243
"args": [
33-
"schema"
44+
"schema",
45+
"--schema-type",
46+
"directory"
3447
]
3548
}
3649
}

resources/filesys/fs.dsc.resource.json renamed to resources/filesys/file.dsc.resource.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json",
3-
"type": "Microsoft.DSC/FileSystem",
3+
"type": "Microsoft.DSC/File",
44
"description": "Manage file system configuration settings.",
55
"version": "0.1.0",
66
"get": {
@@ -15,10 +15,10 @@
1515
"input": "stdin",
1616
"implementsPretest": false
1717
},
18-
"delete": {
19-
"executable": "fs",
18+
"set": {
19+
"executable": "filesys",
2020
"args": [
21-
"delete",
21+
"set",
2222
{
2323
"jsonInputArg": "--input",
2424
"mandatory": true
@@ -28,9 +28,11 @@
2828
},
2929
"schema": {
3030
"command": {
31-
"executable": "fs",
31+
"executable": "filesys",
3232
"args": [
33-
"schema"
33+
"schema",
34+
"--schema-type",
35+
"file"
3436
]
3537
}
3638
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json",
3+
"type": "Microsoft.DSC/FileContent",
4+
"description": "Manage file content configuration settings.",
5+
"version": "0.1.0",
6+
"get": {
7+
"executable": "filesys",
8+
"args": [
9+
"get",
10+
{
11+
"jsonInputArg": "--input",
12+
"mandatory": true
13+
}
14+
],
15+
"input": "stdin",
16+
"implementsPretest": false
17+
},
18+
"delete": {
19+
"executable": "filesys",
20+
"args": [
21+
"delete",
22+
{
23+
"jsonInputArg": "--input",
24+
"mandatory": true
25+
}
26+
],
27+
"input": "stdin"
28+
},
29+
"set": {
30+
"executable": "filesys",
31+
"args": [
32+
"set",
33+
{
34+
"jsonInputArg": "--input",
35+
"mandatory": true
36+
}
37+
],
38+
"input": "stdin"
39+
},
40+
"schema": {
41+
"command": {
42+
"executable": "filesys",
43+
"args": [
44+
"schema",
45+
"--schema-type",
46+
"file-content"
47+
]
48+
}
49+
}
50+
}

resources/filesys/src/args.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clap::{Parser, Subcommand};
88

99
pub struct Args {
1010
#[clap(subcommand)]
11-
pub subcommand: SubCommand,
11+
pub subcommand: SubCommand
1212
}
1313

1414
#[derive(Debug, PartialEq, Eq, Subcommand)]
@@ -25,11 +25,29 @@ pub enum SubCommand {
2525
input: String,
2626
},
2727

28+
#[clap(name = "set", about = "Set the current state of file or directory.", arg_required_else_help = true)]
29+
Set {
30+
#[clap(short, long, required = true, help = "The path to the file or directory.")]
31+
input : String,
32+
},
33+
2834
#[clap(name = "export", about = "Exports the files and directories under the specified path", arg_required_else_help = true)]
2935
Export {
3036
#[clap(short, long, required = true, help = "The path to the file or directory.")]
31-
path: String,
37+
input: String,
3238
},
39+
3340
#[clap(name = "schema", about = "Retrieve JSON schema.")]
34-
Schema,
35-
}
41+
Schema {
42+
#[clap(short, long, default_value = "file", help = "The type of schema to retrieve.")]
43+
schema_type: FileSystemObjectType,
44+
}
45+
}
46+
47+
#[derive(Clone, Default, Debug, PartialEq, Eq, clap::ValueEnum)]
48+
pub enum FileSystemObjectType {
49+
#[default]
50+
File,
51+
Directory,
52+
FileContent,
53+
}

resources/filesys/src/config.rs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,60 @@ pub struct File {
1515
pub size: Option<u64>,
1616

1717
/// The file hash.
18-
pub hash: String,
18+
pub hash: Option<String>,
1919

2020
#[serde(rename = "_exist", skip_serializing_if = "Option::is_none")]
2121
pub exist: Option<bool>,
2222
}
2323

24-
2524
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Hash)]
2625
#[serde(rename ="Directory", deny_unknown_fields)]
2726
pub struct Directory {
2827
/// The path to the directory.
2928
pub path: String,
3029

3130
/// The directory size.
32-
pub size: u64,
31+
#[serde(skip_serializing_if = "Option::is_none")]
32+
pub size: Option<u64>,
3333

3434
/// The files under the directory.
35-
pub files: Vec<File>,
35+
#[serde(skip_serializing_if = "Option::is_none")]
36+
pub files: Option<Vec<File>>,
37+
38+
/// Recurse into subdirectories.
39+
pub recurse: bool,
40+
41+
#[serde(rename = "_exist", skip_serializing_if = "Option::is_none")]
42+
pub exist: Option<bool>,
43+
}
44+
45+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Hash)]
46+
#[serde(rename ="FileContent", deny_unknown_fields)]
47+
pub struct FileContent
48+
{
49+
/// The path to the file.
50+
pub path: String,
51+
52+
/// The file hash.
53+
pub hash: String,
54+
55+
/// The file encoding.
56+
pub encoding: Encoding,
57+
58+
/// The file content.
59+
pub content: String,
3660

3761
#[serde(rename = "_exist", skip_serializing_if = "Option::is_none")]
3862
pub exist: Option<bool>,
63+
}
64+
65+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Hash)]
66+
pub enum Encoding {
67+
Utf8,
68+
Utf16,
69+
Utf32,
70+
Ascii,
71+
Base64,
72+
Hex,
73+
Binary,
3974
}

0 commit comments

Comments
 (0)