# TSK-0042: Standardize File Operations with PathOperations

**Type**: Task
**Status**: Open
**Priority**: High
**Assignee**: Engineer Agent
**Created**: 2025-07-24
**Epic**: Utility Module Integration Phase 3

## Description

Replace all direct file operations using `os.path`, `shutil`, and raw `open()` calls with PathOperations utility to ensure consistent, safe, and cross-platform file handling.

## Acceptance Criteria

- [ ] Replace direct `os.path` usage in 34 identified files
- [ ] Replace `shutil` operations with PathOperations methods
- [ ] Standardize file I/O operations with safe file handling
- [ ] Add atomic write operations where data integrity is critical
- [ ] Implement proper error handling for all file operations
- [ ] Ensure cross-platform compatibility

## Technical Details

### Priority Targets:
1. **parent_directory_manager/backup_manager.py**:
   - Replace `shutil.copy2` with PathOperations.copy_file
   - Add atomic operations for backup integrity

2. **framework_claude_md_generator/deployment_manager.py**:
   - Standardize path joining and file writing
   - Add validation for deployment paths

3. **Service managers with file I/O**:
   - Replace raw `open()` with PathOperations context managers
   - Add proper exception handling

### Implementation Pattern:
```python
# Before:
import os
import shutil
file_path = os.path.join(dir_path, filename)
shutil.copy2(src, dst)
with open(file_path, 'w') as f:
    f.write(content)

# After:
from claude_mpm.utils.path_operations import PathOperations
path_ops = PathOperations()
file_path = path_ops.join_paths(dir_path, filename)
path_ops.copy_file(src, dst)
path_ops.write_file(file_path, content, atomic=True)
```

## Dependencies
- PathOperations from `claude_mpm.utils.path_operations`
- No external dependencies

## Testing Requirements
- Test all file operations for correctness
- Verify atomic write functionality
- Test cross-platform path handling
- Ensure proper error handling
- Add unit tests for edge cases

## Success Metrics
- 100% of direct file operations replaced
- Zero file corruption issues
- Improved error handling coverage
- Cross-platform test suite passing