Skip to content

Commit 5a78cca

Browse files
fatbobmanclaude
andcommitted
debug: add comprehensive ZIP path calculation logging
Added detailed logging to diagnose ZIP structure issues in SPM environments: - Log directory and file paths before and after symlink resolution - Show relative path calculation results - Display all ZIP entries being created - Force output regardless of DEBUG configuration This will help identify why ZIP structures may still be incorrect in certain environments. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b10d747 commit 5a78cca

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

Sources/Objects2XLSX/Utils/SimpleZip.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ public struct SimpleZip: Sendable {
294294
private static func collectEntries(from directoryURL: URL) throws -> [Entry] {
295295
let fileManager = FileManager.default
296296
var entries: [Entry] = []
297+
298+
print("🔧 ZIP collectEntries started from: \(directoryURL.path)")
297299

298300
let enumerator = fileManager.enumerator(
299301
at: directoryURL,
@@ -315,9 +317,21 @@ public struct SimpleZip: Sendable {
315317
if resolvedFileURL.path.hasPrefix(resolvedDirectoryURL.path) {
316318
let basePath = resolvedDirectoryURL.path.hasSuffix("/") ? resolvedDirectoryURL.path : resolvedDirectoryURL.path + "/"
317319
relativePath = String(resolvedFileURL.path.dropFirst(basePath.count))
320+
// 强制输出调试信息(移除 DEBUG 条件)
321+
print("✅ ZIP Path calculation success:")
322+
print(" Directory: \(resolvedDirectoryURL.path)")
323+
print(" File: \(resolvedFileURL.path)")
324+
print(" Relative: \(relativePath)")
318325
} else {
319326
// Fallback to just filename if path calculation fails
320327
relativePath = fileURL.lastPathComponent
328+
// 强制输出调试信息(移除 DEBUG 条件)
329+
print("❌ ZIP Path calculation failed:")
330+
print(" Directory original: \(directoryURL.path)")
331+
print(" Directory resolved: \(resolvedDirectoryURL.path)")
332+
print(" File original: \(fileURL.path)")
333+
print(" File resolved: \(resolvedFileURL.path)")
334+
print(" Fallback to: \(relativePath)")
321335
}
322336
let data = try Data(contentsOf: fileURL)
323337
let modificationDate = resourceValues.contentModificationDate ?? Date()
@@ -327,7 +341,12 @@ public struct SimpleZip: Sendable {
327341
}
328342

329343
// Sort entries by path for consistent output
330-
return entries.sorted { $0.path < $1.path }
344+
let sortedEntries = entries.sorted { $0.path < $1.path }
345+
print("📦 ZIP collectEntries completed: \(sortedEntries.count) files")
346+
for entry in sortedEntries {
347+
print(" 📄 \(entry.path)")
348+
}
349+
return sortedEntries
331350
}
332351
}
333352

debug_paths.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
// 添加这个调试代码到你的项目中测试
4+
func debugPathResolution() {
5+
let tempURL = FileManager.default.temporaryDirectory.appendingPathComponent("test.xlsx")
6+
let tempDir = FileManager.default.temporaryDirectory.appendingPathComponent("Objects2XLSX_DEBUG")
7+
8+
print("🔍 路径调试信息:")
9+
print("1. tempURL.path: \(tempURL.path)")
10+
print("2. tempURL.resolvingSymlinksInPath().path: \(tempURL.resolvingSymlinksInPath().path)")
11+
print("3. tempDir.path: \(tempDir.path)")
12+
print("4. tempDir.resolvingSymlinksInPath().path: \(tempDir.resolvingSymlinksInPath().path)")
13+
14+
// 创建一个测试文件来验证路径
15+
try? FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true)
16+
let testFile = tempDir.appendingPathComponent("test.xml")
17+
try? "test".write(to: testFile, atomically: true, encoding: .utf8)
18+
19+
print("5. testFile.path: \(testFile.path)")
20+
print("6. testFile.resolvingSymlinksInPath().path: \(testFile.resolvingSymlinksInPath().path)")
21+
22+
// 检查前缀匹配
23+
let resolved1 = tempDir.resolvingSymlinksInPath().path
24+
let resolved2 = testFile.resolvingSymlinksInPath().path
25+
print("7. hasPrefix check: \(resolved2.hasPrefix(resolved1))")
26+
27+
// 清理
28+
try? FileManager.default.removeItem(at: tempDir)
29+
}

0 commit comments

Comments
 (0)