Skip to content

Commit

Permalink
add the result of calling lstat() to the processed paths log
Browse files Browse the repository at this point in the history
Summary:
To understand why Watchman is reporting deleted files as existing, log
the results of `getFileInformation()` to the processed paths log.

Reviewed By: kmancini

Differential Revision: D28300181

fbshipit-source-id: 39e7f3fdc1669f8ba0473491d884c081a86b862a
  • Loading branch information
chadaustin authored and facebook-github-bot committed May 8, 2021
1 parent 1faaf29 commit c36efb7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
21 changes: 16 additions & 5 deletions InMemoryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,29 @@ void ViewDatabase::insertAtHeadOfFileList(struct watchman_file* file) {
}

InMemoryView::PendingChangeLogEntry::PendingChangeLogEntry(
const PendingChange& pc) noexcept {
now = pc.now;
flags = pc.flags;
storeTruncatedTail(path_tail, pc.path);
const PendingChange& pc,
std::error_code errcode,
const FileInformation& st) noexcept {
this->now = pc.now;
this->pending_flags = pc.flags;
storeTruncatedTail(this->path_tail, pc.path);

this->errcode = errcode.value();
this->mode = st.mode;
this->size = st.size;
this->mtime = st.mtime.tv_sec;
}

json_ref InMemoryView::PendingChangeLogEntry::asJsonValue() const {
return json_object({
{"now", json_integer(now.time_since_epoch().count())},
{"flags", json_integer(flags)},
{"pending_flags", json_integer(pending_flags)},
{"path",
w_string_to_json(w_string{path_tail, strnlen(path_tail, kPathLength)})},
{"errcode", json_integer(errcode)},
{"mode", json_integer(mode)},
{"size", json_integer(size)},
{"mtime", json_integer(mtime)},
});
}

Expand Down
16 changes: 13 additions & 3 deletions InMemoryView.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,29 @@ class InMemoryView : public QueryableView {
PendingChangeLogEntry() noexcept {
// time_point is not noexcept so this can't be defaulted.
}
explicit PendingChangeLogEntry(const PendingChange& pc) noexcept;
explicit PendingChangeLogEntry(
const PendingChange& pc,
std::error_code errcode,
const FileInformation& st) noexcept;

json_ref asJsonValue() const;

// 55 should cover many filenames.
static constexpr size_t kPathLength = 55;

// fields from PendingChange
std::chrono::system_clock::time_point now;
unsigned char flags;
unsigned char pending_flags;
char path_tail[kPathLength];

// results of calling getFileInformation
int32_t errcode;
mode_t mode;
off_t size;
time_t mtime;
};

static_assert(64 == sizeof(PendingChangeLogEntry));
static_assert(88 == sizeof(PendingChangeLogEntry));

// If set, paths processed by processPending are logged here.
std::unique_ptr<folly::LockFreeRingBuffer<PendingChangeLogEntry>>
Expand Down
4 changes: 0 additions & 4 deletions root/iothread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,6 @@ void InMemoryView::processPath(
pending.path.size() >= rootPath_.size(),
"full_path must be a descendant of the root directory\n");

if (processedPaths_) {
processedPaths_->write(PendingChangeLogEntry{pending});
}

/* From a particular query's point of view, there are four sorts of cookies we
* can observe:
* 1. Cookies that this query has created. This marks the end of this query's
Expand Down
4 changes: 4 additions & 0 deletions root/stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ void InMemoryView::statPath(
}
}

if (processedPaths_) {
processedPaths_->write(PendingChangeLogEntry{pending, errcode, st});
}

if (errcode == watchman::error_code::no_such_file_or_directory ||
errcode == watchman::error_code::not_a_directory) {
/* it's not there, update our state */
Expand Down

0 comments on commit c36efb7

Please sign in to comment.