Skip to content

Commit

Permalink
2023-11-19 17:42:22
Browse files Browse the repository at this point in the history
  • Loading branch information
uidHUB committed Nov 19, 2023
1 parent bb36096 commit 8e6c50c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 28 deletions.
14 changes: 7 additions & 7 deletions PkgStore.Vault.psm1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$ModuleManifest = (Get-ChildItem -Path $PSScriptRoot | Where-Object {$_.Extension -eq '.psd1'})
$ModuleManifest = (Get-ChildItem -Path $PSScriptRoot | Where-Object { $_.Extension -eq '.psd1' })
$CurrentManifest = (Test-ModuleManifest $ModuleManifest)

$Aliases = @()
$PrivateFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') | Where-Object {$_.Extension -eq '.ps1'})
$PublicFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') | Where-Object {$_.Extension -eq '.ps1'})
$PrivateFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') | Where-Object { $_.Extension -eq '.ps1' })
$PublicFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') | Where-Object { $_.Extension -eq '.ps1' })

(@($PrivateFunctions) + @($PublicFunctions)) | ForEach-Object {
try {
Expand All @@ -25,10 +25,10 @@ $PublicFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') | Whe
}
}

$FunctionsAdded = ($PublicFunctions | Where-Object {$_.BaseName -notin $CurrentManifest.ExportedFunctions.Keys})
$FunctionsRemoved = ($CurrentManifest.ExportedFunctions.Keys | Where-Object {$_ -notin $PublicFunctions.BaseName})
$AliasesAdded = ($Aliases | Where-Object {$_ -notin $CurrentManifest.ExportedAliases.Keys})
$AliasesRemoved = ($CurrentManifest.ExportedAliases.Keys | Where-Object {$_ -notin $Aliases})
$FunctionsAdded = ($PublicFunctions | Where-Object { $_.BaseName -notin $CurrentManifest.ExportedFunctions.Keys })
$FunctionsRemoved = ($CurrentManifest.ExportedFunctions.Keys | Where-Object { $_ -notin $PublicFunctions.BaseName })
$AliasesAdded = ($Aliases | Where-Object { $_ -notin $CurrentManifest.ExportedAliases.Keys })
$AliasesRemoved = ($CurrentManifest.ExportedAliases.Keys | Where-Object { $_ -notin $Aliases })

if ($FunctionsAdded -or $FunctionsRemoved -or $AliasesAdded -or $AliasesRemoved) {
try {
Expand Down
8 changes: 8 additions & 0 deletions Private/Compress-VaultData.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
function Compress-VaultData() {
<#
.SYNOPSIS
Compressing data.
.DESCRIPTION
Compressing the Vault data with compression level 9.
#>

param(
[Alias('P')][string]$Path,
[Alias('N')][string]$Name,
Expand Down
8 changes: 8 additions & 0 deletions Private/Start-VaultMoveFiles.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
function Start-VaultMoveFiles() {
<#
.SYNOPSIS
Moving files.
.DESCRIPTION
Moving files from the Source to the Vault.
#>

param(
[string]$Mode,
[string]$Source,
Expand Down
8 changes: 8 additions & 0 deletions Private/Start-VaultRemoveDirs.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
function Start-VaultRemoveDirs() {
<#
.SYNOPSIS
Removing directories.
.DESCRIPTION
Removing empty directories in the Source.
#>

param(
[string]$Source,
[long]$CreationTime,
Expand Down
82 changes: 61 additions & 21 deletions Public/Start-Vault.ps1
Original file line number Diff line number Diff line change
@@ -1,34 +1,74 @@
function Start-Vault {
param(
[Parameter(HelpMessage="Script operation mode. Default: 'MV'.")]
[ValidateSet('CP', 'MV', 'RM')]
[Alias('M')][string]$Mode = 'MV',
<#
.SYNOPSIS
PowerShell Vault.
[Parameter(Mandatory, HelpMessage="Path to the source. E.g.: 'C:\Data\Source'.")]
[Alias('SRC')][string]$Source,
.DESCRIPTION
The module moves files to Vault based on various criteria.
[Parameter(Mandatory, HelpMessage="Path to the Vault. E.g.: 'C:\Data\Vault'.")]
[Alias('DST')][string]$Vault,
.PARAMETER Mode
Script operation mode:
'CP' | Coping data from the Source.
'MV' | Moving data from the Source.
'RM' | Only removing data from the Source.
Default: 'MV'.
[Parameter(HelpMessage="Time since file creation (in seconds). E.g.: '5270400'. Default: 61 day (5270400 sec.).")]
[Alias('CT')][long]$CreationTime = 5270400,
.PARAMETER Source
Path to the source. E.g.: 'C:\Source'.
[Parameter(HelpMessage="Time since file modification (in seconds). E.g.: '5270400'. Default: 61 day ('5270400' sec.).")]
[Alias('WT')][long]$LastWriteTime = $CreationTime,
.PARAMETER Vault
Path to the Vault. E.g.: 'D:\Vault'.
[Parameter(HelpMessage="File size check. E.g.: '5kb' / '12mb'. Default: '0kb'.")]
[Alias('FS')][string]$FileSize = '0kb',
.PARAMETER CreationTime
Time since file creation (in seconds). E.g.: '5270400'.
If the time since file creation is greater than the specified value, they will be processed by the script.
Default: '5270400' (61 day).
[Parameter(HelpMessage="Path to the file with exceptions. E.g.: 'C:\Data\exclude.txt'.")]
[Alias('E')][string]$Exclude = "$(Join-Path (Split-Path $PSScriptRoot -Parent) 'Vault.Exclude.txt')",
.PARAMETER LastWriteTime
Time since file modification (in seconds). E.g.: '5270400'.
If the time since file modification is greater than the specified value, they will be processed by the script.
Default: '5270400' (61 day).
[Parameter(HelpMessage="Path to the directory with logs. E.g.: 'C:\Data\Logs'.")]
[Alias('L')][string]$Logs = "$(Join-Path (Split-Path $PSScriptRoot -Parent) 'Logs')",
.PARAMETER FileSize
File size check. E.g.: '5kb' / '12mb'.
If the file size is greater than the specified value, they will be processed by the script.
Default: '0kb'.
[Parameter(HelpMessage="Removing empty directories.")]
[Alias('RD')][switch]$RemoveDirs = $false,
.PARAMETER Exclude
Path to the file with exceptions. E.g.: 'C:\Exclude.TXT'.
The values specified in this file will be ignored by the script. Wildcards are supported.
.PARAMETER Logs
Path to the directory with logs. E.g.: 'C:\Logs'.
.PARAMETER RemoveDirs
Removing empty directories.
Default: 'false'.
.PARAMETER Overwrite
Overwrite existing files in Vault.
Default: 'false'.
[Parameter(HelpMessage="Overwrite existing files in Vault.")]
.EXAMPLE
Start-Vault -Source 'C:\Source' -Vault 'D:\Vault'
.EXAMPLE
Start-Vault -Source 'C:\Source' -Vault 'D:\Vault' -CreationTime '864000' -LastWriteTime '864000'
.EXAMPLE
Start-Vault -Source 'C:\Source' -Vault 'D:\Vault' -CreationTime '864000' -LastWriteTime '864000' -FileSize '32mb'
#>

param(
[ValidateSet('CP', 'MV', 'RM')][Alias('M')][string]$Mode = 'MV',
[Parameter(Mandatory)][Alias('SRC')][string]$Source,
[Parameter(Mandatory)][Alias('DST')][string]$Vault,
[Alias('CT')][long]$CreationTime = 5270400,
[Alias('WT')][long]$LastWriteTime = $CreationTime,
[Alias('FS')][string]$FileSize = '0kb',
[Alias('E')][string]$Exclude = "$(Join-Path (Split-Path $PSScriptRoot -Parent) 'Vault.Exclude.txt')",
[Alias('L')][string]$Logs = "$(Join-Path (Split-Path $PSScriptRoot -Parent) 'Logs')",
[Alias('RD')][switch]$RemoveDirs = $false,
[Alias('O')][switch]$Overwrite = $false
)

Expand Down

0 comments on commit 8e6c50c

Please sign in to comment.