public void DeleteFile(string fileName) { if (!Files.ContainsKey(fileName)) { throw new Exception("No such file"); } string full_path; if (CurrentPath == "/") { full_path = CurrentPath + fileName; } else { full_path = CurrentPath + "/" + fileName; } string owner = Files[fileName].Owner; int response = StorageAPI.GetRequest(Files[fileName].Address, "api/name/delete?path=" + FileSystem.GetUserPathFromFull(owner, full_path) + "&user="******"Error in removing file"); } if (Files[fileName].ReserveAddress != null) { response = StorageAPI.GetRequest(Files[fileName].ReserveAddress, "api/name/delete?path=" + FileSystem.GetUserPathFromFull(owner, full_path) + "&user="******"Error in removing file"); } } FileSystem.db.ExecuteNonQuery("DELETE FROM files WHERE full_path='" + full_path + "'"); FileSystem.db.ExecuteNonQuery("DELETE FROM file_to_dir WHERE file_path='" + full_path + "'"); Files.Remove(fileName); }
public void RegFile(string name, string size, string storageId, string owner) { string mainAddress = FileSystem.db.GetStorageAddressById(storageId); string filePath; if (CurrentPath == "/") { filePath = CurrentPath + name; } else { filePath = CurrentPath + "/" + name; } List <string> excludedId = new List <string>(); excludedId.Add(storageId); int response = 0; bool foundReserve = false; string reserveId = ""; string reserveAddress = ""; do { reserveId = FileSystem.db.ChooseReplicateStorage(size, excludedId); if (reserveId != "") { reserveAddress = FileSystem.db.GetStorageAddressById(reserveId); response = StorageAPI.GetRequest(reserveAddress, "api/name/replicate?path=" + FileSystem.GetUserPathFromFull(owner, CurrentPath) + "&name=" + name + "&target=" + mainAddress + "&user="******""); DirFile file = new DirFile(name, mainAddress); file.Size = size; file.Owner = owner; Files.Add(name, file); if (foundReserve) { FileSystem.db.ExecuteNonQuery("INSERT INTO files(full_path, dir_path, name, addr, size, reserv_addr, owner) VALUES ('" + filePath + "', '" + CurrentPath + "', '" + name + "', '" + mainAddress + "', '" + size + "', '" + reserveAddress + "', '" + owner + "')"); Files[name].ReserveAddress = reserveAddress; FileSystem.db.UpdateStorageFreeSpace(reserveId, size); } else { FileSystem.db.ExecuteNonQuery("INSERT INTO files(full_path, dir_path, name, addr, size, owner) VALUES ('" + filePath + "', '" + CurrentPath + "', '" + name + "', '" + mainAddress + "', '" + size + "', '" + owner + "')"); } FileSystem.db.ExecuteNonQuery("INSERT INTO file_to_dir(dir_path, file_path) VALUES ('" + CurrentPath + "', '" + filePath + "')"); }
public void DeleteSubDir(string deletedName) { if (!Directories.ContainsKey(deletedName)) { throw new Exception("No such directory"); } Directory deletedDir = Directories[deletedName]; List <string> dirStorages = GetDirStorages(deletedDir); for (int i = 0; i < dirStorages.Count; ++i) { int response = StorageAPI.GetRequest(dirStorages[i], "/api/name/deletedir?path=" + FileSystem.GetUserPathFromFull(deletedDir.Owner, deletedDir.CurrentPath) + "&user="******"Error in removing directory"); } } FileSystem.db.ExecuteNonQuery("DELETE FROM files WHERE dir_path='" + deletedDir.CurrentPath + "'"); FileSystem.db.ExecuteNonQuery("DELETE FROM file_to_dir WHERE dir_path='" + deletedDir.CurrentPath + "'"); FileSystem.db.ExecuteNonQuery("DELETE FROM dirs WHERE curr_path='" + deletedDir.CurrentPath + "'"); Directories.Remove(deletedName); }