Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(758)

Unified Diff: sql/sqlite_features_unittest.cc

Issue 2626823008: [sql] Move time-machine support from third_party/sqlite to sql/ (Closed)
Patch Set: ps output Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sql/connection.cc ('k') | sql/vfs_wrapper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/sqlite_features_unittest.cc
diff --git a/sql/sqlite_features_unittest.cc b/sql/sqlite_features_unittest.cc
index 199d9446c73b14ba452297f1c9b317ddcd1565c1..2e1ea33bf9a5fec49df198b7a69618eba985253d 100644
--- a/sql/sqlite_features_unittest.cc
+++ b/sql/sqlite_features_unittest.cc
@@ -22,6 +22,14 @@
#include "base/ios/ios_util.h"
#endif
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+#include <CoreFoundation/CoreFoundation.h>
+#include <CoreServices/CoreServices.h>
+
+#include "base/mac/mac_util.h"
+#include "base/mac/scoped_cftyperef.h"
+#endif
+
// Test that certain features are/are-not enabled in our SQLite.
namespace {
@@ -303,4 +311,90 @@ TEST_F(SQLiteFeaturesTest, CachedRegexp) {
EXPECT_EQ(7, s.ColumnInt(0));
}
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+CFURLRef CFURLRefForPath(const base::FilePath& path){
+ base::ScopedCFTypeRef<CFStringRef> urlString(
+ CFStringCreateWithFileSystemRepresentation(
+ kCFAllocatorDefault, path.value().c_str()));
+ return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, urlString,
+ kCFURLPOSIXPathStyle, FALSE);
+}
+
+void gross() {
+ CFPreferencesSetAppValue(CFSTR("CSBackupDebugLogging"),
+ kCFBooleanTrue,
+ kCFPreferencesCurrentApplication);
+}
+
+// If a database file is marked to be excluded from Time Machine, verify that
+// journal files are also excluded.
+TEST_F(SQLiteFeaturesTest, TimeMachine) {
+ gross();
+ LOG(ERROR) << __FUNCTION__ << " geteuid() " << geteuid();
+ ASSERT_TRUE(db().Execute("CREATE TABLE t (id INTEGER PRIMARY KEY)"));
+ db().Close();
+
+ {
+ LOG(ERROR) << "Mount output:";
+ FILE* m = popen("mount", "r");
+ if (!m) {
+ PLOG(ERROR) << "Failed to open mount";
+ } else {
+ char buf[1024];
+ while (fgets(buf, sizeof(buf), m)) {
+ size_t l = strlen(buf);
+ if (buf[l - 1] == '\n')
+ buf[l - 1] = '\0';
+ LOG(ERROR) << buf;
+ }
+ pclose(m);
+ }
+ }
+ {
+ LOG(ERROR) << "Ps output:";
+ FILE* m = popen("ps ax", "r");
+ if (!m) {
+ PLOG(ERROR) << "Failed to open ps";
+ } else {
+ char buf[1024];
+ while (fgets(buf, sizeof(buf), m)) {
+ size_t l = strlen(buf);
+ if (buf[l - 1] == '\n')
+ buf[l - 1] = '\0';
+ LOG(ERROR) << buf;
+ }
+ pclose(m);
+ }
+ }
+ base::FilePath journal(db_path().value() + FILE_PATH_LITERAL("-journal"));
+ ASSERT_TRUE(GetPathExists(db_path()));
+ ASSERT_TRUE(GetPathExists(journal));
+
+ base::ScopedCFTypeRef<CFURLRef> dbURL(CFURLRefForPath(db_path()));
+ base::ScopedCFTypeRef<CFURLRef> journalURL(CFURLRefForPath(journal));
+
+ // Not excluded to start.
+ EXPECT_FALSE(CSBackupIsItemExcluded(dbURL, NULL));
+ EXPECT_FALSE(CSBackupIsItemExcluded(journalURL, NULL));
+
+ // Exclude the main database file.
+ EXPECT_TRUE(base::mac::SetFileBackupExclusion(db_path()));
+
+ Boolean excluded_by_path = FALSE;
+ EXPECT_TRUE(CSBackupIsItemExcluded(dbURL, &excluded_by_path));
+ EXPECT_FALSE(excluded_by_path);
+ EXPECT_FALSE(CSBackupIsItemExcluded(journalURL, NULL));
+
+ EXPECT_TRUE(db().Open(db_path()));
+ ASSERT_TRUE(db().Execute("INSERT INTO t VALUES (1)"));
+ EXPECT_TRUE(CSBackupIsItemExcluded(dbURL, &excluded_by_path));
+ EXPECT_FALSE(excluded_by_path);
+ EXPECT_TRUE(CSBackupIsItemExcluded(journalURL, &excluded_by_path));
+ EXPECT_FALSE(excluded_by_path);
+
+ // TODO(shess): In WAL mode this will touch -wal and -shm files. -shm files
+ // could be always excluded.
+}
+#endif
+
} // namespace
« no previous file with comments | « sql/connection.cc ('k') | sql/vfs_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698