# OWCPatchingTool — Migrate Data Folder to Upload Mode

A small Go CLI that safely copies installer files and metadata from an old, versionless storage layout to a new, versioned layout by inserting a VERSION path component into each destination path.

## Layouts

Old (source)
```
<old-root>/<Signature>/<Analog ID>/<Arch>/<Language>/installer_file
```

New (destination)
```
<new-root>/<Signature>/<Analog ID>/<VERSION>/<Arch>/<Language>/installer_file
```

## Features
- Dry-run mode to preview every copy operation without modifying files.
- Recursively discovers installer files under the old root and copies them while preserving subfolders.
- Derives and inserts the appropriate version string into each destination package path.

## Usage
From the tool folder, run:
```
migrator.exe -input-path <source_path> -output-path <destination_path> [-dry-run=true|false]
```

Flags
- `-input-path` (required)  
    Root of the existing, versionless structure (e.g. `/data/storage/windows`).
- `-output-path` (required)  
    Root where the new, versioned structure will be created.
- `-dry-run` (optional, default: `true`)  
    If `true`, the tool prints planned copy actions only. Set to `false` to perform the actual copy.

## Examples

Preview migration (no files changed):
```
migrator.exe -input-path /data/storage/windows -output-path /data/storage_v2 -dry-run=true
```

Perform migration:
```
migrator.exe -input-path /data/storage/windows -output-path /data/storage_v2 -dry-run=false
```

Windows example (note escaping or quoting of backslashes):
```
migrator.exe -input-path "C:\ProgramData\OPSWAT\Security Controls\Console\Patches" -output-path . -dry-run=true
migrator.exe -input-path "C:\ProgramData\OPSWAT\Security Controls\Console\Patches" -output-path . -dry-run=false
```

When run locally, the tool writes to an output folder called `migration_output` with this structure:
```
migration_output/
├── packages/   # bundle(s) prepared for upload mode
└── windows/    # new data layout for folder mode (versioned)
```

## Recommended workflow
1. Run with `-dry-run=true` and inspect the planned operations.
2. Back up critical data before making bulk changes.
3. Run with `-dry-run=false` to execute the migration.
4. Spot-check migrated packages in the new layout.

## Troubleshooting
- Permission errors: ensure read access on the old root and write access on the new root.
- Path separators: quote Windows paths or use double backslashes in shells that require escaping.
- Large migrations: test on a small subset first and monitor disk space and I/O.

