Skip to content

Commit 0e045a6

Browse files
committed
Merge branch 'main' of github.com:pilvikala/cloud-archive
2 parents a0406be + 93dc726 commit 0e045a6

4 files changed

Lines changed: 44 additions & 22 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cloud-archive",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "A CLI tool",
55
"main": "dist/index.js",
66
"bin": {

src/lib/sync-client.test.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ describe("SyncClient", () => {
5959
expect(result.uploadedFiles).toHaveLength(3);
6060
expect(result.totalFilesUploaded).toBe(3);
6161
expect(result.uploadedFiles).toContain(
62-
path.join(destinationPath, "file1.txt")
62+
path.join(destinationPath, "file1.txt").replace(/\\/g, "/")
6363
);
6464
expect(result.uploadedFiles).toContain(
65-
path.join(destinationPath, "file2.txt")
65+
path.join(destinationPath, "file2.txt").replace(/\\/g, "/")
6666
);
6767
expect(result.uploadedFiles).toContain(
68-
path.join(destinationPath, "subdir/file3.txt")
68+
path.join(destinationPath, "subdir/file3.txt").replace(/\\/g, "/")
6969
);
7070

7171
// Verify uploadFile was called for each file with correct destination paths
7272
expect(mockGcpClient.uploadFile).toHaveBeenCalledTimes(3);
7373
expect(mockGcpClient.uploadFile).toHaveBeenCalledWith(
7474
path.join(tempDir, "file1.txt"),
75-
path.join(destinationPath, "file1.txt")
75+
path.join(destinationPath, "file1.txt").replace(/\\/g, "/")
7676
);
7777
expect(mockGcpClient.listContent).toHaveBeenCalledTimes(1);
7878
expect(mockGcpClient.listContent).toHaveBeenCalledWith(
@@ -83,15 +83,15 @@ describe("SyncClient", () => {
8383

8484
it("should skip existing files with same size", async () => {
8585
// Mock existing files in bucket
86-
const file1Stats = await fs.promises.stat(path.join(tempDir, "file1.txt"));
86+
const file1Stats = await fs.promises.stat(path.join(tempDir, "file1.txt").replace(/\\/g, "/"));
8787
const file3Stats = await fs.promises.stat(
88-
path.join(tempDir, "subdir", "file3.txt")
88+
path.join(tempDir, "subdir", "file3.txt").replace(/\\/g, "/")
8989
);
9090

9191
mockGcpClient.listContent.mockResolvedValueOnce([
92-
{ name: path.join(destinationPath, "file1.txt"), size: file1Stats.size },
92+
{ name: path.join(destinationPath, "file1.txt").replace(/\\/g, "/"), size: file1Stats.size },
9393
{
94-
name: path.join(destinationPath, "subdir/file3.txt"),
94+
name: path.join(destinationPath, "subdir/file3.txt").replace(/\\/g, "/"),
9595
size: file3Stats.size,
9696
},
9797
]);
@@ -103,14 +103,14 @@ describe("SyncClient", () => {
103103
expect(result.uploadedFiles).toHaveLength(1);
104104
expect(result.totalFilesUploaded).toBe(1);
105105
expect(result.uploadedFiles).toContain(
106-
path.join(destinationPath, "file2.txt")
106+
path.join(destinationPath, "file2.txt").replace(/\\/g, "/")
107107
);
108108

109109
// Verify uploadFile was called only once with correct destination path
110110
expect(mockGcpClient.uploadFile).toHaveBeenCalledTimes(1);
111111
expect(mockGcpClient.uploadFile).toHaveBeenCalledWith(
112112
path.join(tempDir, "file2.txt"),
113-
path.join(destinationPath, "file2.txt")
113+
path.join(destinationPath, "file2.txt").replace(/\\/g, "/")
114114
);
115115
});
116116

@@ -129,11 +129,11 @@ describe("SyncClient", () => {
129129

130130
// Verify file1.txt was uploaded again due to size difference
131131
expect(result.uploadedFiles).toContain(
132-
path.join(destinationPath, "file1.txt")
132+
path.join(destinationPath, "file1.txt").replace(/\\/g, "/")
133133
);
134134
expect(mockGcpClient.uploadFile).toHaveBeenCalledWith(
135135
path.join(tempDir, "file1.txt"),
136-
path.join(destinationPath, "file1.txt")
136+
path.join(destinationPath, "file1.txt").replace(/\\/g, "/")
137137
);
138138
});
139139

@@ -157,23 +157,23 @@ describe("SyncClient", () => {
157157
// Verify all files are uploaded to the correct destination path
158158
expect(result.uploadedFiles).toHaveLength(3);
159159
expect(result.uploadedFiles).toEqual([
160-
path.join(destinationPath, "file1.txt"),
161-
path.join(destinationPath, "file2.txt"),
162-
path.join(destinationPath, "subdir/file3.txt"),
160+
path.join(destinationPath, "file1.txt").replace(/\\/g, "/"),
161+
path.join(destinationPath, "file2.txt").replace(/\\/g, "/"),
162+
path.join(destinationPath, "subdir/file3.txt").replace(/\\/g, "/"),
163163
]);
164164

165165
// Verify uploadFile was called with correct destination paths
166166
expect(mockGcpClient.uploadFile).toHaveBeenCalledWith(
167167
path.join(tempDir, "file1.txt"),
168-
path.join(destinationPath, "file1.txt")
168+
path.join(destinationPath, "file1.txt").replace(/\\/g, "/")
169169
);
170170
expect(mockGcpClient.uploadFile).toHaveBeenCalledWith(
171171
path.join(tempDir, "file2.txt"),
172-
path.join(destinationPath, "file2.txt")
172+
path.join(destinationPath, "file2.txt").replace(/\\/g, "/")
173173
);
174174
expect(mockGcpClient.uploadFile).toHaveBeenCalledWith(
175175
path.join(tempDir, "subdir/file3.txt"),
176-
path.join(destinationPath, "subdir/file3.txt")
176+
path.join(destinationPath, "subdir/file3.txt").replace(/\\/g, "/")
177177
);
178178

179179
// Verify listContent was called with the correct destination path
@@ -182,4 +182,26 @@ describe("SyncClient", () => {
182182
destinationPath
183183
);
184184
});
185+
186+
it("should return paths with forward slashes even on Windows", async () => {
187+
// Create a nested directory structure with backslashes
188+
const nestedDir = path.join(tempDir, "nested", "deep", "dir");
189+
await fs.promises.mkdir(nestedDir, { recursive: true });
190+
await fs.promises.writeFile(
191+
path.join(nestedDir, "test.txt"),
192+
"test content"
193+
);
194+
195+
// Get the files using listFiles
196+
const files = await (syncClient as any).listFiles();
197+
198+
// Find the nested file path
199+
const nestedFilePath = files.find(([_, path]: [string, string]) => path.includes("test.txt"))?.[1];
200+
201+
// Verify the nested path uses forward slashes
202+
expect(nestedFilePath).not.toContain("\\");
203+
expect(nestedFilePath).toContain("/");
204+
expect(nestedFilePath).toBe("nested/deep/dir/test.txt");
205+
});
206+
185207
});

src/lib/sync-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class SyncClient {
3636

3737
for (const entry of entries) {
3838
const fullPath = path.join(currentPath, entry.name);
39-
const newRelativePath = path.join(relativePath, entry.name);
39+
const newRelativePath = path.join(relativePath, entry.name).replace(/\\/g, "/");
4040

4141
if (entry.isDirectory()) {
4242
await processDirectory(fullPath, newRelativePath);
@@ -66,7 +66,7 @@ export class SyncClient {
6666

6767
for (const [absolutePath, relativePath] of files) {
6868
const stats = await fs.promises.stat(absolutePath);
69-
const destinationPath = path.join(this.destinationPath, relativePath);
69+
const destinationPath = path.join(this.destinationPath, relativePath).replace(/\\/g, "/");
7070
const existingSize = existingFilesMap.get(destinationPath);
7171

7272
if (!existingSize || existingSize !== stats.size) {

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const version = "v1.1.2";
1+
export const version = "v1.1.3";

0 commit comments

Comments
 (0)