1 /* Copyright 2012-present Facebook, Inc.
2  * Licensed under the Apache License, Version 2.0 */
3 #pragma once
4 
5 struct watchman_file {
6   /* the parent dir */
7   watchman_dir *parent;
8 
9   /* linkage to files ordered by changed time.
10    * prev points to the address of `next` in the
11    * previous file node, or the head of the list. */
12   struct watchman_file **prev, *next;
13 
14   /* linkage to files ordered by common suffix.
15    * suffix_prev points to the address of `suffix_next`
16    * in the previous file node, or the head of the
17    * suffix list. */
18   struct watchman_file **suffix_prev, *suffix_next;
19 
20   /* the time we last observed a change to this file */
21   w_clock_t otime;
22   /* the time we first observed this file OR the time
23    * that this file switched from !exists to exists.
24    * This is thus the "created time" */
25   w_clock_t ctime;
26 
27   /* whether we believe that this file still exists */
28   bool exists;
29   /* whether we think this file might not exist */
30   bool maybe_deleted;
31 
32   /* cache stat results so we can tell if an entry
33    * changed */
34   watchman::FileInformation stat;
35 
36   /* the symbolic link target of this file.
37    * Can be NULL if not a symlink, or we failed to read the target */
38   w_string symlink_target;
39 
getNamewatchman_file40   inline w_string_piece getName() const {
41     auto lenPtr = (uint32_t*)(this + 1);
42     auto data = (char*)(lenPtr + 1);
43     return w_string_piece(data, *lenPtr);
44   }
45 
46   void removeFromFileList();
47 
48   watchman_file() = delete;
49   watchman_file(const watchman_file&) = delete;
50   watchman_file& operator=(const watchman_file&) = delete;
51   ~watchman_file();
52 
53   static std::unique_ptr<watchman_file, watchman_dir::Deleter> make(
54       const w_string& name,
55       watchman_dir* parent);
56 
57  private:
58   void removeFromSuffixList();
59 };
60 
61 void free_file_node(struct watchman_file* file);
62