@gadgetinc/ggt 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { createLogger } from "../output/log/logger.js";
|
|
3
|
-
import { isNil } from "../util/is.js";
|
|
4
3
|
const log = createLogger({
|
|
5
4
|
name: "hashes"
|
|
6
5
|
});
|
|
@@ -119,22 +118,25 @@ export class ChangesWithHash extends Map {
|
|
|
119
118
|
}
|
|
120
119
|
return necessaryChanges;
|
|
121
120
|
};
|
|
122
|
-
export const isEqualHash = (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
121
|
+
export const isEqualHash = (_path, aHash, bHash)=>{
|
|
122
|
+
// FIXME: we're running into issues syncing permissions with Gadget
|
|
123
|
+
// so we're temporarily disabling this check until we can figure out
|
|
124
|
+
return aHash.sha1 === bHash.sha1;
|
|
125
|
+
// if (aHash.sha1 !== bHash.sha1) {
|
|
126
|
+
// // the contents are different
|
|
127
|
+
// return false;
|
|
128
|
+
// }
|
|
129
|
+
// if (path.endsWith("/")) {
|
|
130
|
+
// // it's a directory, so we don't care about permissions
|
|
131
|
+
// return true;
|
|
132
|
+
// }
|
|
133
|
+
// if (isNil(aHash.permissions) || isNil(bHash.permissions)) {
|
|
134
|
+
// // one of the filesystems doesn't support permissions, so ignore them
|
|
135
|
+
// return true;
|
|
136
|
+
// }
|
|
137
|
+
// // the contents are the same, and both filesystems support permissions
|
|
138
|
+
// // so ensure the permissions are also the same
|
|
139
|
+
// return aHash.permissions === bHash.permissions;
|
|
138
140
|
};
|
|
139
141
|
export const isEqualHashes = (a, b)=>{
|
|
140
142
|
for (const [aPath, aHash] of Object.entries(a)){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/filesync/hashes.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport { createLogger } from \"../output/log/logger.js\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/services/filesync/hashes.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport { createLogger } from \"../output/log/logger.js\";\nimport { type Create, type Delete, type Update } from \"./changes.js\";\nimport type { Hash, Hashes } from \"./directory.js\";\n\nconst log = createLogger({ name: \"hashes\" });\n\nexport type CreateWithHash = Create & { targetHash: Hash };\nexport type UpdateWithHash = Update & { sourceHash: Hash; targetHash: Hash };\nexport type DeleteWithHash = Delete & { sourceHash: Hash };\nexport type ChangeWithHash = CreateWithHash | UpdateWithHash | DeleteWithHash;\n\nexport class ChangesWithHash extends Map<string, ChangeWithHash> {\n created(): string[] {\n return Array.from(this.entries())\n .filter(([, change]) => change.type === \"create\")\n .map(([path]) => path);\n }\n\n updated(): string[] {\n return Array.from(this.entries())\n .filter(([, change]) => change.type === \"update\")\n .map(([path]) => path);\n }\n\n deleted(): string[] {\n return Array.from(this.entries())\n .filter(([, change]) => change.type === \"delete\")\n .map(([path]) => path);\n }\n}\n\n/**\n * Calculates the changes that were made to `from` to make it end up as `to`.\n *\n * If `existing` is provided, only the changes that are necessary to\n * apply to `existing` are returned.\n *\n * If `ignore` is provided, any changes that were made to a path that\n * starts with any of the `ignore` paths are skipped.\n */\nexport const getChanges = ({\n from: source,\n to: target,\n existing,\n ignore,\n}: {\n from: Hashes;\n to: Hashes;\n existing?: Hashes;\n ignore?: string[];\n}): ChangesWithHash => {\n const changes = new ChangesWithHash();\n const targetPaths = Object.keys(target);\n\n for (const [sourcePath, sourceHash] of Object.entries(source)) {\n if (ignore?.some((ignored) => sourcePath.startsWith(ignored))) {\n continue;\n }\n\n const targetHash = target[sourcePath];\n if (!targetHash) {\n if (!sourcePath.endsWith(\"/\") || !targetPaths.some((targetPath) => targetPath.startsWith(sourcePath))) {\n // sourcePath is a file and it doesn't exist in target OR\n // sourcePath is a directory and target doesn't have any\n // existing files inside it, therefor the sourcePath has been\n // deleted\n changes.set(sourcePath, { type: \"delete\", sourceHash });\n log.trace(\"file deleted\", { path: sourcePath, sourceHash });\n }\n } else if (!isEqualHash(sourcePath, sourceHash, targetHash)) {\n // the file or directory exists in target, but has a different\n // hash, so it's been updated\n changes.set(sourcePath, { type: \"update\", sourceHash, targetHash });\n log.trace(\"file updated\", { path: sourcePath, sourceHash, targetHash });\n }\n }\n\n for (const targetPath of targetPaths) {\n if (ignore?.some((ignored) => targetPath.startsWith(ignored))) {\n continue;\n }\n\n if (!source[targetPath]) {\n // the targetPath doesn't exist in source, so it's been created\n const targetHash = target[targetPath];\n assert(targetHash, \"targetHash should exist\");\n\n changes.set(targetPath, { type: \"create\", targetHash });\n log.trace(\"file created\", { path: targetPath, targetHash });\n }\n }\n\n if (!existing) {\n return changes;\n }\n\n return withoutUnnecessaryChanges({ changes, existing });\n};\n\n/**\n * Filters out changes that the existing filesystem already has.\n */\nexport const withoutUnnecessaryChanges = ({ changes, existing }: { changes: ChangesWithHash; existing: Hashes }): ChangesWithHash => {\n const necessaryChanges = new ChangesWithHash();\n\n for (const [path, change] of changes) {\n const existingHash = existing[path];\n if (change.type === \"delete\" && !existingHash) {\n // already deleted\n log.trace(\"already deleted\", { path });\n continue;\n }\n\n if (change.type !== \"delete\" && existingHash && isEqualHash(path, change.targetHash, existingHash)) {\n // already created or updated\n log.trace(\"already created or updated\", { path, existingHash, targetHash: change.targetHash });\n continue;\n }\n\n // we could do this:\n // if (change.type === \"update\" && !existingHash) {\n // change = { type: \"create\", targetHash: change.targetHash };\n // }\n // but, changing the type makes the output look confusing and it\n // doesn't change the outcome, so we just leave it as is\n\n necessaryChanges.set(path, change);\n }\n\n return necessaryChanges;\n};\n\nexport const isEqualHash = (_path: string, aHash: Hash, bHash: Hash): boolean => {\n // FIXME: we're running into issues syncing permissions with Gadget\n // so we're temporarily disabling this check until we can figure out\n return aHash.sha1 === bHash.sha1;\n\n // if (aHash.sha1 !== bHash.sha1) {\n // // the contents are different\n // return false;\n // }\n\n // if (path.endsWith(\"/\")) {\n // // it's a directory, so we don't care about permissions\n // return true;\n // }\n\n // if (isNil(aHash.permissions) || isNil(bHash.permissions)) {\n // // one of the filesystems doesn't support permissions, so ignore them\n // return true;\n // }\n\n // // the contents are the same, and both filesystems support permissions\n // // so ensure the permissions are also the same\n // return aHash.permissions === bHash.permissions;\n};\n\nexport const isEqualHashes = (a: Hashes, b: Hashes): boolean => {\n for (const [aPath, aHash] of Object.entries(a)) {\n const bHash = b[aPath];\n if (!bHash || !isEqualHash(aPath, aHash, bHash)) {\n log.debug(\"hashes are not equal\", { path: aPath, aHash, bHash });\n return false;\n }\n }\n\n for (const bPath of Object.keys(b)) {\n if (!a[bPath]) {\n log.debug(\"hashes are not equal\", { path: bPath, aHash: undefined, bHash: b[bPath] });\n return false;\n }\n }\n\n return true;\n};\n"],"names":["assert","createLogger","log","name","ChangesWithHash","Map","created","Array","from","entries","filter","change","type","map","path","updated","deleted","getChanges","source","to","target","existing","ignore","changes","targetPaths","Object","keys","sourcePath","sourceHash","some","ignored","startsWith","targetHash","endsWith","targetPath","set","trace","isEqualHash","withoutUnnecessaryChanges","necessaryChanges","existingHash","_path","aHash","bHash","sha1","isEqualHashes","a","b","aPath","debug","bPath","undefined"],"mappings":"AAAA,OAAOA,YAAY,cAAc;AACjC,SAASC,YAAY,QAAQ,0BAA0B;AAIvD,MAAMC,MAAMD,aAAa;IAAEE,MAAM;AAAS;AAO1C,OAAO,MAAMC,wBAAwBC;IACnCC,UAAoB;QAClB,OAAOC,MAAMC,IAAI,CAAC,IAAI,CAACC,OAAO,IAC3BC,MAAM,CAAC,CAAC,GAAGC,OAAO,GAAKA,OAAOC,IAAI,KAAK,UACvCC,GAAG,CAAC,CAAC,CAACC,KAAK,GAAKA;IACrB;IAEAC,UAAoB;QA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EA,OAAO4B;AACT,EAAE;AAEF,OAAO,MAAMF,cAAc,CAACI,OAAeC,OAAaC;IACtD,mEAAmE;IACnE,oEAAoE;IACpE,OAAOD,MAAME,IAAI,KAAKD,MAAMC,IAAI;AAEhC,mCAAmC;AACnC,kCAAkC;AAClC,kBAAkB;AAClB,IAAI;AAEJ,4BAA4B;AAC5B,4DAA4D;AAC5D,iBAAiB;AACjB,IAAI;AAEJ,8DAA8D;AAC9D,0EAA0E;AAC1E,iBAAiB;AACjB,IAAI;AAEJ,yEAAyE;AACzE,iDAAiD;AACjD,kDAAkD;AACpD,EAAE;AAEF,OAAO,MAAMC,gBAAgB,CAACC,GAAWC;IACvC,KAAK,MAAM,CAACC,OAAON,MAAM,IAAIjB,OAAOhB,OAAO,CAACqC,GAAI;QAC9C,MAAMH,QAAQI,CAAC,CAACC,MAAM;QACtB,IAAI,CAACL,SAAS,CAACN,YAAYW,OAAON,OAAOC,QAAQ;YAC/CzC,IAAI+C,KAAK,CAAC,wBAAwB;gBAAEnC,MAAMkC;gBAAON;gBAAOC;YAAM;YAC9D,OAAO;QACT;IACF;IAEA,KAAK,MAAMO,SAASzB,OAAOC,IAAI,CAACqB,GAAI;QAClC,IAAI,CAACD,CAAC,CAACI,MAAM,EAAE;YACbhD,IAAI+C,KAAK,CAAC,wBAAwB;gBAAEnC,MAAMoC;gBAAOR,OAAOS;gBAAWR,OAAOI,CAAC,CAACG,MAAM;YAAC;YACnF,OAAO;QACT;IACF;IAEA,OAAO;AACT,EAAE"}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gadgetinc/ggt",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@gadgetinc/ggt",
|
|
9
|
-
"version": "0.4.
|
|
9
|
+
"version": "0.4.6",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@sentry/node": "^7.88.0",
|