Skip to content

Commit

Permalink
Remove unused fs code.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Oct 24, 2019
1 parent fdb562b commit 96bba58
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 244 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ target_sources(ccls PRIVATE
src/message_handler.cc
src/platform_posix.cc
src/platform_win.cc
src/platform.cc
src/port.cc
src/position.cc
src/project.cc
Expand Down
6 changes: 3 additions & 3 deletions src/import_pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ long long GetCurrentTimeInMilliseconds() {
struct ActiveThread {
ActiveThread(ImportPipelineStatus* status)
: status_(status) {
if (g_config->progressReportFrequencyMs < 0)
if (g_config && g_config->progressReportFrequencyMs < 0)
return;

++status_->num_active_threads;
}
~ActiveThread() {
if (g_config->progressReportFrequencyMs < 0)
if (g_config && g_config->progressReportFrequencyMs < 0)
return;

--status_->num_active_threads;
Expand All @@ -122,7 +122,7 @@ struct ActiveThread {
out.params.activeThreads = status_->num_active_threads;

// Ignore this progress update if the last update was too recent.
if (g_config->progressReportFrequencyMs != 0) {
if (g_config && g_config->progressReportFrequencyMs != 0) {
// Make sure we output a status update if queue lengths are zero.
bool all_zero =
out.params.indexRequestCount == 0 && out.params.doIdMapCount == 0 &&
Expand Down
5 changes: 3 additions & 2 deletions src/messages/initialize.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "cache_manager.h"
#include "diagnostics_engine.h"
#include "filesystem.hh"
#include "import_pipeline.h"
#include "include_complete.h"
#include "message_handler.h"
Expand Down Expand Up @@ -504,9 +505,9 @@ struct Handler_Initialize : BaseMessageHandler<In_InitializeRequest> {
config->projectRoot = project_path;
// Create two cache directories for files inside and outside of the
// project.
MakeDirectoryRecursive(config->cacheDirectory +
fs::create_directories(config->cacheDirectory +
EscapeFileName(config->projectRoot));
MakeDirectoryRecursive(config->cacheDirectory + '@' +
fs::create_directories(config->cacheDirectory + '@' +
EscapeFileName(config->projectRoot));

g_config = std::move(config);
Expand Down
96 changes: 0 additions & 96 deletions src/platform.cc

This file was deleted.

28 changes: 0 additions & 28 deletions src/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,18 @@
#include <string>
#include <vector>

struct PlatformMutex {
virtual ~PlatformMutex();
};
struct PlatformScopedMutexLock {
virtual ~PlatformScopedMutexLock();
};
struct PlatformSharedMemory {
virtual ~PlatformSharedMemory();
void* data;
size_t capacity;
std::string name;
};

void PlatformInit();

std::string GetExecutablePath();
std::string GetWorkingDirectory();
std::string NormalizePath(const std::string& path);
// Creates a directory at |path|. Creates directories recursively if needed.
void MakeDirectoryRecursive(std::string path);
// Tries to create the directory given by |absolute_path|. Returns true if
// successful or if the directory already exists. Returns false otherwise. This
// does not attempt to recursively create directories.
bool TryMakeDirectory(const std::string& absolute_path);

void SetCurrentThreadName(const std::string& thread_name);

std::optional<int64_t> GetLastModificationTime(const std::string& absolute_path);

void MoveFileTo(const std::string& destination, const std::string& source);
void CopyFileTo(const std::string& destination, const std::string& source);

bool IsSymLink(const std::string& path);

// Free any unused memory and return it to the system.
void FreeUnusedMemory();

// If true objective-c index tests will be run.
bool RunObjectiveCIndexTests();

// Stop self and wait for SIGCONT.
void TraceMe();

Expand Down
79 changes: 0 additions & 79 deletions src/platform_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,11 @@ std::string GetExecutablePath() {
#endif
}

std::string GetWorkingDirectory() {
char result[FILENAME_MAX];
if (!getcwd(result, sizeof(result)))
return "";
std::string working_dir = std::string(result, strlen(result));
EnsureEndsInSlash(working_dir);
return working_dir;
}

std::string NormalizePath(const std::string& path) {
std::optional<std::string> resolved = RealPathNotExpandSymlink(path);
return resolved ? *resolved : path;
}

bool TryMakeDirectory(const std::string& absolute_path) {
const mode_t kMode = 0777; // UNIX style permissions
if (mkdir(absolute_path.c_str(), kMode) == -1) {
// Success if the directory exists.
return errno == EEXIST;
}
return true;
}

void SetCurrentThreadName(const std::string& thread_name) {
loguru::set_thread_name(thread_name.c_str());
#if defined(__APPLE__)
Expand Down Expand Up @@ -206,73 +188,12 @@ std::optional<int64_t> GetLastModificationTime(const std::string& absolute_path)
return buf.st_mtime;
}

void MoveFileTo(const std::string& dest, const std::string& source) {
// TODO/FIXME - do a real move.
CopyFileTo(dest, source);
}

// See http://stackoverflow.com/q/13198627
void CopyFileTo(const std::string& dest, const std::string& source) {
int fd_from = open(source.c_str(), O_RDONLY);
if (fd_from < 0)
return;

int fd_to = open(dest.c_str(), O_WRONLY | O_CREAT, 0666);
if (fd_to < 0)
goto out_error;

char buf[4096];
ssize_t nread;
while (nread = read(fd_from, buf, sizeof buf), nread > 0) {
char* out_ptr = buf;
ssize_t nwritten;

do {
nwritten = write(fd_to, out_ptr, nread);

if (nwritten >= 0) {
nread -= nwritten;
out_ptr += nwritten;
} else if (errno != EINTR)
goto out_error;
} while (nread > 0);
}

if (nread == 0) {
if (close(fd_to) < 0) {
fd_to = -1;
goto out_error;
}
close(fd_from);

return;
}

out_error:
close(fd_from);
if (fd_to >= 0)
close(fd_to);
}

bool IsSymLink(const std::string& path) {
struct stat buf;
return lstat(path.c_str(), &buf) == 0 && S_ISLNK(buf.st_mode);
}

void FreeUnusedMemory() {
#if defined(__GLIBC__)
malloc_trim(0);
#endif
}

bool RunObjectiveCIndexTests() {
#if defined(__APPLE__)
return true;
#else
return false;
#endif
}

void TraceMe() {
// If the environment variable is defined, wait for a debugger.
// In gdb, you need to invoke `signal SIGCONT` if you want ccls to continue
Expand Down
31 changes: 0 additions & 31 deletions src/platform_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ std::string GetExecutablePath() {
return NormalizePath(result);
}

// See http://stackoverflow.com/a/19535628
std::string GetWorkingDirectory() {
char result[MAX_PATH];
std::string binary_path(result, GetModuleFileName(NULL, result, MAX_PATH));
return binary_path.substr(0, binary_path.find_last_of("\\/") + 1);
}

std::string NormalizePath(const std::string& path) {
DWORD retval = 0;
TCHAR buffer[MAX_PATH] = TEXT("");
Expand All @@ -57,14 +50,6 @@ std::string NormalizePath(const std::string& path) {
return result;
}

bool TryMakeDirectory(const std::string& absolute_path) {
if (_mkdir(absolute_path.c_str()) == -1) {
// Success if the directory exists.
return errno == EEXIST;
}
return true;
}

// See https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push, 8)
Expand Down Expand Up @@ -117,24 +102,8 @@ std::optional<int64_t> GetLastModificationTime(const std::string& absolute_path)
return buf.st_mtime;
}

void MoveFileTo(const std::string& destination, const std::string& source) {
MoveFile(source.c_str(), destination.c_str());
}

void CopyFileTo(const std::string& destination, const std::string& source) {
CopyFile(source.c_str(), destination.c_str(), false /*failIfExists*/);
}

bool IsSymLink(const std::string& path) {
return false;
}

void FreeUnusedMemory() {}

bool RunObjectiveCIndexTests() {
return false;
}

// TODO Wait for debugger to attach
void TraceMe() {}

Expand Down
8 changes: 4 additions & 4 deletions src/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ bool RunIndexTests(const std::string& filter_path, bool enable_update) {
bool is_fail_allowed = false;

if (EndsWithAny(path, {".m", ".mm"})) {
if (!RunObjectiveCIndexTests()) {
std::cout << "Skipping \"" << path << "\" since this platform does not "
#ifndef __APPLE__
std::cout << "Skipping \"" << path << "\" since this platform does not "
<< "support running Objective-C tests." << std::endl;
continue;
}
continue;
#endif

// objective-c tests are often not updated right away. do not bring down
// CI if they fail.
Expand Down

0 comments on commit 96bba58

Please sign in to comment.