Skip to content

Python: Drop redundant columns from files and folders relations #6708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions python/ql/lib/semmle/python/Files.qll
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import python

/** A file */
class File extends Container {
File() { files(this, _, _, _, _) }

class File extends Container, @file {
/** DEPRECATED: Use `getAbsolutePath` instead. */
deprecated override string getName() { result = this.getAbsolutePath() }

Expand Down Expand Up @@ -34,9 +32,7 @@ class File extends Container {
}

/** Gets a short name for this file (just the file name) */
string getShortName() {
exists(string simple, string ext | files(this, _, simple, ext, _) | result = simple + ext)
}
string getShortName() { result = this.getBaseName() }

private int lastLine() {
result = max(int i | exists(Location l | l.getFile() = this and l.getEndLine() = i))
Expand All @@ -55,7 +51,7 @@ class File extends Container {
)
}

override string getAbsolutePath() { files(this, result, _, _, _) }
override string getAbsolutePath() { files(this, result) }

/** Gets the URL of this file. */
override string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }
Expand Down Expand Up @@ -118,15 +114,10 @@ private predicate occupied_line(File f, int n) {
}

/** A folder (directory) */
class Folder extends Container {
Folder() { folders(this, _, _) }

class Folder extends Container, @folder {
/** DEPRECATED: Use `getAbsolutePath` instead. */
deprecated override string getName() { result = this.getAbsolutePath() }

/** DEPRECATED: Use `getBaseName` instead. */
deprecated string getSimple() { folders(this, _, result) }

/**
* Holds if this element is at the specified location.
* The location spans column `startcolumn` of line `startline` to
Expand All @@ -144,7 +135,7 @@ class Folder extends Container {
endcolumn = 0
}

override string getAbsolutePath() { folders(this, result, _) }
override string getAbsolutePath() { folders(this, result) }

/** Gets the URL of this folder. */
override string getURL() { result = "folder://" + this.getAbsolutePath() }
Expand Down
9 changes: 2 additions & 7 deletions python/ql/lib/semmlecode.python.dbscheme
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,11 @@ svnchurn(
Python dbscheme
****************************/

/* fromSource is ignored */
files(unique int id: @file,
varchar(900) name: string ref,
varchar(900) simple: string ref,
varchar(900) ext: string ref,
int fromSource: int ref);
varchar(900) name: string ref);

folders(unique int id: @folder,
varchar(900) name: string ref,
varchar(900) simple: string ref);
varchar(900) name: string ref);

@container = @folder | @file;

Expand Down
Loading