This module handles uploading files to the vault, including encryption, index updates, and remote repository synchronization.
fmt: String formatting and printingos: Operating system file operations
func UploadFile(sourcePath string, vaultPath string, session *Session) errorUploads a file from the local filesystem to the vault, encrypting it and updating the vault index.
Parameters:
sourcePath: The path to the file on the local filesystem (e.g., "./document.pdf")vaultPath: The destination path in the vault (e.g., "documents/report.pdf")session: The active session containing authentication credentials, encryption password, and vault index
Return:
error: Returns error if file reading, encryption, index update, or push operations fail
Upload Process:
-
Construct Repository URL: Builds the git repository URL from session username
-
Read Source File: Reads the entire file from the local filesystem
- Returns error if file doesn't exist or cannot be read
-
Determine Storage Name:
- Existing Files: Checks if file already exists in vault index
- Uses existing storage ID (RealName)
- Displays "Updating existing file" message
- New Files: Generates new random hex-based storage ID
- Adds entry to vault index with
AddFile() - Displays "Uploading new file" message
- Adds entry to vault index with
- Existing Files: Checks if file already exists in vault index
-
Encrypt File Data:
- Encrypts file using the session password
- Produces encrypted bytes ready for storage
-
Encrypt Updated Index:
- Serializes and encrypts the updated vault index
- Creates
.config/indexentry
-
Prepare Push Package:
- Creates map containing:
- The encrypted file (storage ID as key)
- The encrypted index (
.config/indexas key)
- Creates map containing:
-
Push to Repository:
- Calls
PushFiles()to push both files to GitHub - Uses SSH authentication from session
- Commit message: "Nexus: Updated Vault"
- Calls
File Handling:
New Files:
Local: ./document.pdf
Vault: documents/report.pdf
Storage: a3f2e1c9d4b6f8e2 (hex name, content = encrypted)
Updating Existing Files:
Vault: documents/report.pdf
Storage: (existing hex name - reused)
Action: File content replaced, index unchanged
Error Handling:
- Returns error if source file cannot be read
- Returns error if encryption fails
- Returns error if git push fails
- Returns error if index serialization fails
Example Usage:
// Upload a new file
err := UploadFile("./quarterly_report.pdf", "documents/Q1.pdf", session)
if err != nil {
fmt.Println("Upload failed:", err)
}
// Update an existing file
err = UploadFile("./updated_report.pdf", "documents/Q1.pdf", session)
if err != nil {
fmt.Println("Update failed:", err)
}
// Upload to nested folders (creates folders if needed)
err = UploadFile("./archive.zip", "backups/2024/archive.zip", session)
if err != nil {
fmt.Println("Upload failed:", err)
}Output Examples:
Uploading new file:
Uploading new file: documents/report.pdf as a3f2e1c9d4b6f8e2
Updating existing file:
Updating existing file: documents/report.pdf (a3f2e1c9d4b6f8e2)
The upload process:
- Checks local index cache (not remote) for existing file
- Creates intermediate folders automatically
- Uses stateless push operation (doesn't redownload entire repository)
- Updates both file content and vault index in single push
- Files are encrypted with AES-256-GCM before upload
- Storage IDs are randomly generated (original filenames not exposed)
- Index is encrypted and stored in
.config/index - Encryption key is derived from session password
- No explicit file size limits in the code
- Practical limits depend on GitHub's API and SSH transfer limits
- Large files should be zipped before upload
- If an upload fails mid-process, the local session index may be updated but the push might fail
- The vault index is updated before pushing (optimistic approach)
- Consider saving the session after successful upload
- Intermediate folders are created automatically (no need to pre-create structure)
- Files with the same vault path but different source paths will overwrite
// After connecting to vault
err := UploadFile("./my_document.pdf", "documents/my_document.pdf", session)
if err != nil {
fmt.Println("Upload failed:", err)
return
}
// File is now encrypted and stored in vault
// Index is updated and pushed to GitHub
// Both files and index are synced with remotefunc UploadDirectory(sourceDirPath string, vaultPath string, session *Session) errorUploads an entire directory recursively to the vault, preserving folder structure and encrypting all files.
Parameters:
sourceDirPath: The path to the local directory (e.g., "./documents")vaultPath: The destination path in the vault (e.g., "backups/documents")session: The active session with authentication and encryption credentials
Return:
error: Returns error if directory reading, any file encryption, or push fails
- Verify Directory: Confirms path is a directory, not a file
- Create Vault Path: Creates necessary folder structure in vault index
- Recursively Walk Files: Iterates through all files using
filepath.Walk() - Process Each File:
- Maintains relative paths from source directory
- Reads file content
- Generates new encryption key for each file
- Encrypts with vault password
- Adds entry to vault index
- Collects for batch upload
- Batch Upload: Uploads all files to GitHub in single push
- Index Update: Encrypts and uploads updated vault index
# Upload entire local directory
zep upload ./my-folder vault/my-folder
# Upload project directory
zep upload ./project backup/project
# Upload with custom name
zep upload ./documents archive/docs-backupLocal Directory:
./documents/
report.pdf
notes.txt
subfolder/
memo.pdf
archive.zip
Vault Structure:
vault/documents/
report.pdf
notes.txt
subfolder/
memo.pdf
archive.zip
Scanning directory: ./documents
Processing file (1): report.pdf
→ New file: vault/documents/report.pdf as a3f2e1c9d4b6f8e2
Processing file (2): notes.txt
→ New file: vault/documents/notes.txt as b4g3f2d0e5c7h9f3
Processing file (3): subfolder/memo.pdf
→ New file: vault/documents/subfolder/memo.pdf as c5h4g3e1f6d8i0j4
Uploading 3 files to vault...
[1/2] Encrypting vault index...
[2/2] Uploading to GitHub...
✔ Successfully uploaded 3 files from directory
- ✅ Recursive Processing: Handles nested folders of any depth
- ✅ Per-File Encryption: Each file gets unique encryption key
- ✅ Atomic Upload: All files and index uploaded in single batch
- ✅ Structure Preservation: Folder hierarchy maintained exactly
- ✅ Progress Tracking: Shows file count and processing status
- ✅ Error Handling: Reports failures with detailed context
-
Backup Entire Projects
zep upload ./project backup/my-project
-
Archive Bulk Documents
zep upload ./documents vault/documents-archive
-
Upload Photo Collections
zep upload ./photos vault/photos/2024
zep download: Download entire directorieszep list: View vault structurezep transfer-vault: Migrate directories to another vault