Commit Graph

70 Commits

Author SHA1 Message Date
Allan Odgaard
db13d4c1f9 Use std::string::back() instead of operator[] with size()-1 2014-03-31 08:27:18 +07:00
Allan Odgaard
716b8ea8f3 Add path::unescape to split a shell line into words 2014-03-29 18:58:53 +07:00
Allan Odgaard
c73ad254cb Add path::escape to use when passing paths to a shell interpreter 2014-03-29 18:58:53 +07:00
Allan Odgaard
c3120c15aa Set FD_CLOEXEC immediately after calling mkstemp()
There is still a race condition but it’s a little better than before.
2014-03-29 09:57:10 +07:00
Allan Odgaard
fe59a55750 Do not abort() if we fail to create a pipe
Failure to create a pipe does happen “in the wild” (with the error “too many open files”). Since majority of subprocess executions relate to gathering version control info we can probably ignore the failure, as not having version control info is better than crashing.

OTOH that pipe() fails does seem to be a symptom of a more serious issue.

The io::spawn implementation has also been updated to use io::create_pipe which sets FD_CLOEXEC, so there should be no reason to set this.
2014-03-29 09:57:10 +07:00
Allan Odgaard
7f7613fe62 Change io::create_pipe API
We now return a tuple and always set FD_CLOEXEC.
2014-03-29 09:57:09 +07:00
Allan Odgaard
dac27f7587 Use constants for input, output, and error file descriptors 2014-03-29 09:57:09 +07:00
Allan Odgaard
5881b86775 Support initial content when creating temporary files 2014-03-28 19:31:15 +07:00
Allan Odgaard
cf8f796053 Do not use va_start macro with variable reference
This is undefined according to the standard and is a warning with clang-503.0.38.
2014-03-13 20:51:15 +07:00
Allan Odgaard
c2397484b8 Use C++11 for loop
Majority of the edits done using the following ruby script:

    def update_loops(src)
      dst, cnt = '', 0

      block_indent, variable = nil, nil
      src.each_line do |line|
        if block_indent
          if line =~ /^#{block_indent}([{}\t])|^\t*$/
            block_indent = nil if $1 == '}'
            line = line.gsub(%r{ ([^a-z>]) \(\*#{variable}\) | \*#{variable}\b | \b#{variable}(->) }x) do
              $1.to_s + variable + ($2 == "->" ? "." : "")
            end
          else
            block_indent = nil
          end
        elsif line =~ /^(\t*)c?iterate\((\w+), (?!diacritics::make_range)(.*\))$/
          block_indent, variable = $1, $2
          line = "#$1for(auto const& #$2 : #$3\n"
          cnt += 1
        end
        dst << line
      end
      return dst, cnt
    end

    paths.each do |path|
      src = IO.read(path)

      cnt = 1
      while cnt != 0
        src, cnt = update_loops(src)
        STDERR << "#{path}: #{cnt}\n"
      end

      File.open(path, "w") { |io| io << src }
    end
2014-03-03 10:34:13 +07:00
Allan Odgaard
1f57336da8 Log error when mkdir() fails 2013-12-14 14:22:15 +07:00
Allan Odgaard
20583653f9 Test if io::spawn fails 2013-10-19 21:21:33 +02:00
Allan Odgaard
c602958e66 Don’t stack allocate space for extended attribute values
Seeing a few crashes related to this, most likely because an extended attribute holds a value larger than available stack space.
2013-10-04 16:51:27 +02:00
Allan Odgaard
c5558d0574 Remove a few std::shared_ptr typedefs 2013-10-04 16:51:26 +02:00
Allan Odgaard
d3a78e59f2 Put posix_spawn related failure in crash report 2013-09-05 23:57:03 +02:00
Allan Odgaard
1c308c810d Use map::emplace instead of inserting std::pair (C++11) 2013-09-05 20:59:11 +02:00
Allan Odgaard
e4e80a946c Use std::make_shared 2013-09-03 12:27:20 +02:00
Allan Odgaard
7e6d0b8d1b fixup! Log errors from each call in swap_and_unlink 2013-08-25 21:13:06 +02:00
Allan Odgaard
6889ba9ba7 Log errors from each call in swap_and_unlink 2013-08-23 23:21:16 +02:00
Allan Odgaard
802ea1fc7a Treat most errors from exchangedata() as “not supported”
It seems to be a general trend with network file systems to return wrong errors when they do not support a certain feature (like extended attributes and atomic swap).
2013-08-21 22:20:43 +02:00
Allan Odgaard
9eda1a473b Remove path::identifier_t 2013-07-30 15:44:18 +02:00
Allan Odgaard
0a64d372a9 Improve lstat error message 2013-07-29 16:07:33 +02:00
Allan Odgaard
7ed6199df1 Print error if scandir/lstat fails 2013-07-26 16:26:20 +02:00
Allan Odgaard
115838949a Do not resolve broken symbolic links
Links that would point “above” the root (e.g. ‘/foo’ → ‘../../bar’) would cause an infinite recursion and eventually crash.
2013-07-02 18:43:46 +02:00
Allan Odgaard
ef6082006d Failing to set/remove extended attributes is no longer an error
Workaround for osxfuse/osxfuse#85 (and possibly other file systems).
2013-05-26 10:24:35 +08:00
Allan Odgaard
7f88fcbdf3 Fix problem with opening multiple empty files on FAT file systems
The problem is that empty files on a FAT file system all have the same inode so TextMate would consider them to be links of each other and only show the last one opened.

Fixes #979.
2013-05-15 16:17:06 +07:00
Allan Odgaard
58dc0b0491 Remove path::walker_t
The intent of this class was to allow ad-hoc recursive/lazy walking of a directory structure and having links only visited once.

It was however only used once, and for that task, path::entries() is sufficient.
2013-05-15 15:45:36 +07:00
Allan Odgaard
bf7d657eef Move some TM variables to oak::basic_environment 2013-05-12 11:09:18 +07:00
Allan Odgaard
ec9208afa9 Use whitelist feature to preserve dialog variables 2013-05-12 11:09:18 +07:00
Allan Odgaard
950cb8b27a Only lock mutex for critical code 2013-03-25 10:25:59 +01:00
Allan Odgaard
8ce1c48fe7 Introduce io::spawn API
This is a wrapper for posix_spawn that sets up pipes for stdin, out, and error.
2013-03-21 14:39:34 +01:00
Allan Odgaard
957d6d018d Don’t treat directories as executables
Related to issue #907.
2013-03-19 14:56:22 +01:00
Allan Odgaard
beb5348e32 Don’t abort when failing to run subcommand
Fixes #907.
2013-03-19 14:56:22 +01:00
Allan Odgaard
0d2af1fbfa Don’t use posix_spawnattr_setpgroup
This appears to fail in rare circumstances and there is no reason why the io::exec code sets up a process group, so easier to just remove this.
2013-03-17 15:44:07 +01:00
Allan Odgaard
dfee671b6a Don’t use POSIX_SPAWN_CLOEXEC_DEFAULT on 10.7
Using this flag on 10.7.5 seems to cause a kernel panic.

Fixes #896.
2013-03-17 15:44:06 +01:00
Allan Odgaard
24f6f3bd2c Use posix_spawn instead of fork/exec
Using Apple’s POSIX_SPAWN_CLOEXEC_DEFAULT appears to be the only safe way to spawn a child process in a multi-threaded program.
2013-03-10 16:07:11 +01:00
Allan Odgaard
f69ac60b0c Limit file descriptors passed to child process
Instead of passing the file descriptor to the child, and have the child close it, we set FD_CLOEXEC on the file descriptor in the parent process.

While it limits the window in which another thread can fork() and cause the file descriptor to be “leaked”, it doesn’t eliminate the problem.
2013-03-10 16:07:10 +01:00
Allan Odgaard
13edc6d131 Use O_CLOEXEC when opening files
This avoids leaking file descriptors into child processes, which would otherwise happen if another thread forks while the file descriptor is open.
2013-03-10 16:07:10 +01:00
Allan Odgaard
cd2b0882f0 Use new test system for a few frameworks 2013-02-22 15:55:28 +01:00
Allan Odgaard
972348687c Make fs-events wrapper thread safe
Previously this wasn’t used from multiple threads, but with the new testing system it can be.
2013-02-22 15:51:51 +01:00
Allan Odgaard
f05c76a882 Implement path::join for initializer lists
This allows passing multiple path components to path::join
2013-02-12 11:09:24 +01:00
Allan Odgaard
099fbdf042 Accept NULL_STR in path::info 2013-02-11 14:21:21 +01:00
Allan Odgaard
9eb4044fdb Switch to simpler regexp::search 2013-02-08 11:20:35 +01:00
Allan Odgaard
bb6d003e4f Read environment variable whitelist from user defaults
This is read using the ‘environmentWhitelist’ key and the value should be a colon-separated list of variables that should be inherited from TextMate’s parent process. If the variable includes an asterisk then it is matched as a glob.

Example:

    defaults write com.macromates.TextMate.preview environmentWhitelist '$default:MANPATH:*EDITOR'

Here ‘$default’ will expand to TextMate’s default whitelist.

Normally TextMate will setup HOME, PATH, TMPDIR, LOGNAME, and USER. If you whitelist any of these, then the variable (if set) will instead be inherited from the parent process.

Closes #718.
2013-02-08 11:20:34 +01:00
Allan Odgaard
759e4d9720 Introduce path::is_child(child, parent)
This also returns true when ‘child == parent’ so perhaps a better name should be chosen for this function.
2013-02-05 15:25:45 +01:00
Allan Odgaard
b0c4363c48 Introduce path::cache
This gives the cache location — this one is not cleaned as often as the temp directory.
2013-01-21 15:03:52 +01:00
Allan Odgaard
6bdf883abf fixup! Optimize path::disambiguate 2013-01-20 12:49:34 +01:00
Allan Odgaard
edbf9ac079 Optimize path::disambiguate
We now sort the reversed paths and do a linear sweep.
2013-01-17 09:16:04 +01:00
Allan Odgaard
3bee6cf5c6 Use path before inode to determine file identity
Previously when opening a file TextMate only looked at the (cached) inode of the open documents to learn if the requested file was already open. This could result in opening two versions of the same file e.g. after ‘git rebase’ as git will write new files with new inodes when updating the working copy.

Closes issue #666.
2013-01-13 13:02:46 +01:00
Allan Odgaard
da6afa03f0 Fix concurrency bug in path::make_dir
The function could fail if the directory was created after the function had tested that it didn’t exist, as the mkdir() would then fail (with “Already Exists”).
2012-09-30 23:06:58 +02:00