This module handles file and folder deletion operations in the Nexus vault, managing both the index and git repository.
fmt: String formatting and printingstrings: String manipulation utilitiestime: Time package for commit timestampsgithub.com/go-git/go-billy/v5/memfs: In-memory filesystemgithub.com/go-git/go-git/v5: Git operations librarygithub.com/go-git/go-git/v5/config: Git configurationgithub.com/go-git/go-git/v5/plumbing: Git plumbing operationsgithub.com/go-git/go-git/v5/plumbing/object: Git object typesgithub.com/go-git/go-git/v5/plumbing/transport/ssh: SSH transport for gitgithub.com/go-git/go-git/v5/storage/memory: In-memory git storagegolang.org/x/crypto/ssh: SSH cryptography utilities
func DeletePath(vaultPath string, session *Session) errorHandles both single file deletion and recursive folder deletion from the vault. This function performs the following operations:
Parameters:
vaultPath: The path to the file or folder to delete (e.g., "folder/file.txt")session: The active session containing authentication credentials and vault index
Return:
error: Returns an error if any operation fails (navigation, git operations, or index updates)
Process:
- Navigate to Target: Parses the vault path and navigates through the index to locate the target file or folder
- Identify Files to Delete:
- For files: Collects the single file's storage ID
- For folders: Recursively collects all nested file storage IDs
- Git Setup:
- Clones the vault git repository using SSH authentication
- Creates an in-memory filesystem and storage
- Remove Files: Physically removes all collected files from the git worktree
- Update Index: Removes the target entry from the vault index
- Push Changes:
- Writes the updated index to git
- Commits changes with author information
- Pushes the commit back to the remote master branch
Error Handling:
- Returns an error if a path component is not found
- Returns an error if the target path doesn't exist in the vault
- Skips files that are already gone from the remote
- Returns an error if git operations fail
Example Usage:
err := DeletePath("documents/report.pdf", session)
if err != nil {
fmt.Println("Delete failed:", err)
}Notes:
- The function uses SSH authentication with the user's SSH key stored in the session
- Supports recursive deletion of entire folders and all their contents
- All changes are automatically committed and pushed to the vault repository
- The vault index is updated to reflect the deletion