MCPcopy
hub / github.com/meteor/meteor / readAndWatchFileWithHash

Function readAndWatchFileWithHash

tools/fs/watch.ts:845–882  ·  view source on GitHub ↗
(watchSet: WatchSet, absPath: string)

Source from the content-addressed store, hash-verified

843// *rely* on the hash being returned; merely that if the hash is
844// present, it is the correct hash of the contents.
845export function readAndWatchFileWithHash(watchSet: WatchSet, absPath: string) {
846 const result: {
847 contents: string | Buffer | null;
848 hash: string | null;
849 } = {
850 contents: null,
851 hash: null,
852 };
853
854 try {
855 result.contents = files.readFile(absPath);
856 } catch (e) {
857 if (e && e.code === "EISDIR") {
858 // Avoid adding directories to the watchSet as files.
859 return result;
860 }
861
862 if (e && e.code === "ENOENT") {
863 // Continue, leaving result.{contents,hash} both null.
864 } else {
865 // Throw all other errors.
866 throw e;
867 }
868 }
869
870 if (result.contents !== null) {
871 result.hash = sha1(result.contents);
872 }
873
874 // Allow null watchSet, if we want to use readFile-style error handling in a
875 // context where we might not always have a WatchSet (eg, reading
876 // settings.json where we watch for "meteor run" but not for "meteor deploy").
877 if (watchSet) {
878 watchSet.addFile(absPath, result.hash);
879 }
880
881 return result;
882}
883
884export function readAndWatchFile(watchSet: WatchSet, absPath: string) {
885 return readAndWatchFileWithHash(watchSet, absPath).contents;

Callers 2

readAndWatchFileFunction · 0.85

Calls 3

sha1Function · 0.85
readFileMethod · 0.45
addFileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…